HTML
JPG
PDF
XML
DOCX
PDF
How to delete pages from PDF documents using Cloud .NET SDK
In order to delete pages from 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 delete pages using .NET SDK
Aspose.PDF Cloud developers can easily load & delete pages from 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.
- Delete page from PDF in cloud storage.
- Checks the response and logs the result.
- Downloads the updated file for local use.
This sample code shows deleting pages from PDF document
using Aspose.Pdf.Cloud.Sdk.Model;
namespace Pages
{
public class PagesDelete
{
public static async Task Delete(string documentName, string outputName, int pageNumber, 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]);
}
// Delete page from the PDF on cloud storage.
AsposeResponse response = await pdfApi.DeletePageAsync(documentName, pageNumber, folder: remoteFolder);
// Checks the response and logs the result.
if (response == null)
Console.WriteLine("PagesDelete(): Unexpected error!");
else if (response.Code < 200 || response.Code > 299)
Console.WriteLine("PagesDelete(): Failed to delete page from the document.");
else
{ // Downloads the updated file for local use.
Console.WriteLine("PagesDelete(): page successfully deleted from the document '{0}.", documentName);
Stream stream = pdfApi.DownloadFile(Path.Combine(remoteFolder, documentName));
using var fileStream = File.Create(Path.Combine(localFolder, "delete_pages_" + outputName));
stream.Position = 0;
await stream.CopyToAsync(fileStream);
Console.WriteLine("PagesDelete(): File '{0}' successfully downloaded.", "delete_pages_" + outputName);
}
}
}
}