Skip to content

Instantly share code, notes, and snippets.

How to Crop a PDF using C#. For further details: https://kb.conholdate.com/total/net/how-to-crop-a-pdf-using-csharp/
static void Main(string[] args) // Crop a PDF page in C#
{
// Set the license
new Aspose.Pdf.License().SetLicense("Aspose.Total.lic");
Aspose.Pdf.Document pdfDoc = new Aspose.Pdf.Document("ImageAndText.pdf");
System.Console.WriteLine(pdfDoc.Pages[1].CropBox);
System.Console.WriteLine(pdfDoc.Pages[1].TrimBox);
System.Console.WriteLine(pdfDoc.Pages[1].ArtBox);
System.Console.WriteLine(pdfDoc.Pages[1].BleedBox);
System.Console.WriteLine(pdfDoc.Pages[1].MediaBox);
// Create a new Box Rectangle
Aspose.Pdf.Rectangle rect = new Aspose.Pdf.Rectangle(190, 210, 2060, 1430);
pdfDoc.Pages[1].CropBox = rect;
pdfDoc.Pages[1].TrimBox = rect;
pdfDoc.Pages[1].ArtBox = rect;
pdfDoc.Pages[1].BleedBox = rect;
pdfDoc.Save("cropped_modified.pdf");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment