HTML
JPG
PDF
XML
DOCX
PDF
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.
- Create a new Configuration object with your Application Secret and Key.
- Create an object to connect to the Cloud API.
- Uploads the PDF to cloud storage.
- Append a new page to the PDF in cloud storage.
- Checks the response and logs the result.
- 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);
}
}