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
using Aspose.Pdf.Cloud.Sdk.Model;
namespace Pages
{
public class PagesAdd
{
public static async Task Append(string documentName, string outputName, string localFolder, string remoteFolder)
{
// Get your AppSid and AppSecret from https://dashboard.aspose.cloud (free registration required).
pdfApi = new PdfApi(AppSecret, AppSid);
using (var file = File.OpenRead(Path.Combine(localFolder, documentName)))
{ // Upload the local PDF to cloud storage folder name.
FilesUploadResult uploadResponse = await pdfApi.UploadFileAsync(Path.Combine(remoteFolder, documentName), documentName);
Console.WriteLine(uploadResponse.Uploaded[0]);
}
// Append new page to the PDF on cloud storage.
DocumentPagesResponse response = await pdfApi.PutAddNewPageAsync(documentName, folder: remoteFolder);
// Checks the response and logs the result.
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
{ // Downloads the updated file for local use.
Console.WriteLine("PagesAdd(): page successfully appended to the document '{0}.", documentName);
Stream stream = pdfApi.DownloadFile(Path.Combine(remoteFolder, documentName));
using var fileStream = File.Create(Path.Combine(localFolder, "append_pages_" + outputName));
stream.Position = 0;
await stream.CopyToAsync(fileStream);
Console.WriteLine("PagesAdd(): File '{0}' successfully downloaded.", "append_pages_" + outputName);
}
}
}
}