HTML
JPG
PDF
XML
DOCX
PDF
Crop PDF documents in .NET SDK
API for trimming unwanted arareas in PDF documents using Aspose.PDF Cloud .NET SDK.
Get StartedHow to crop PDF docuemnts via Cloud .NET SDK
To crop PDF documents, 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 crop PDF using .NET SDK
Aspose.PDF Cloud developers can easily load & crop PDF in just a few lines of code.
- Upload the PDF File to Cloud.
- Get Page Info.
- Extract the Page as an Image.
- Create a New Empty PDF Document.
- Insert the Image into the New PDF.
- Download the Final Cropped PDF.
Crop PDF using .NET Cloud SDK
public async Task CropDocumentPages()
{
const string localPdfDocument = @"C:\Samples\sample.pdf";
const string storageFileName = "sample.pdf";
const string localFolder = @"C:\Samples";
const string resultFileName = "output_cropped.pdf";
// Get your AppSid and AppSecret from https://dashboard.aspose.cloud (free registration required).
pdfApi = new PdfApi(AppSecret, AppSid);
using var file = File.OpenRead(localPdfDocument);
await pdfApi.UploadFileAsync(storageFileName, file);
var response = await pdfApi.PostDocumentPagesCropAsync(storageFileName, "1,3-5,8", new Rectangle(300.0, 150.0, 500.0, 200.0));
if (response == null)
Console.WriteLine("CropDocumentPages(): Unexpected error!");
else if (response.Code < 200 || response.Code > 299)
Console.WriteLine("CropDocumentPages(): Failed to crop Pdf document pages.");
else
{
await (await pdfApi.DownloadFileAsync(storageFileName))
.CopyToAsync( File.Create(Path.Combine(localFolder, resultFileName)));
Console.WriteLine("CropDocumentPages(): successfully cropped PDF document '{0}' pages.", resultFileName);
}
}