HTML JPG PDF XML DOCX
  Product Family
PDF

Add New Pages to PDF via .NET SDK

API for adding pages to PDF documents with .NET.

Get Started

How to append pages to PDF documents using Cloud .NET SDK

In order to add pages to PDF documents via Cloud .NET SDK , we’ll use Aspose.PDF Cloud .NET SDK This Cloud SDK allows you to easily build cloud-based PDF creator, editor & converter apps in C#, ASP.NET, or other .NET languages for various cloud platforms. Open NuGet package manager, search for Aspose.PDF Cloud and install. You may also use the following command from the Package Manager Console.

Package Manager Console Command


    PM> Install-Package Aspose.Pdf-Cloud
     

Steps to add pages using .NET SDK

Aspose.PDF Cloud developers can easily load & append pages to PDF documents in just a few lines of code.

  1. Create a new Configuration object with your Application Secret and Key.
  2. Create an object to connect to the Cloud API.
  3. Uploads the PDF to cloud storage.
  4. Append a new page to the PDF in cloud storage.
  5. Checks the response and logs the result.
  6. Downloads the updated file for local use.
 

This sample code shows adding pages to PDF document


    public static async Task AddPage()
	{
	    const string localPdfFileName = @"C:\Samples\sample.pdf";
	    const string storageFileName = "sample.pdf";
	    const string localFolder = @"C:\Samples";
	    const string resultFileName = "output_add_page.pdf";
	    const string storageTempFolder = "YourTempFolder";

	    // Get your AppSid and AppSecret https://dashboard.aspose.cloud (free registration required).
	    var pdfApi = new PdfApi(AppSecret, AppSid);

	    using var file = File.OpenRead(localPdfFileName);
	    var uploadResult = pdfApi.UploadFile(Path.Combine(storageTempFolder, storageFileName), file);
	    Console.WriteLine(uploadResult.Uploaded[0]);

	    DocumentPagesResponse response = await pdfApi.PutAddNewPageAsync(storageFileName, folder: storageTempFolder);

	    if (response == null)
	        Console.WriteLine("PagesAdd(): Unexpected error!");
	    else if (response.Code < 200 || response.Code > 299)
	        Console.WriteLine("PagesAdd(): Failed to append page to the document.");
	    else
	    {
	        using Stream downloadStream = pdfApi.DownloadFile(Path.Combine(storageTempFolder, storageFileName));
	        using FileStream localStream = File.Create(Path.Combine(localFolder, resultFileName));
	        downloadStream.CopyTo(localStream);
	        Console.WriteLine("PagesAdd(): page successfully appended to the document '{0}.", resultFileName);
	    }
	}