Rohit
Rohit

Reputation: 61

How to crop a Pdf with printer/crop marks

The Example PDF is: PDF

Using Aspose.PDF for .NET, I'm trying to crop a PDF which has white spaces around the edges, and printer/crop marks. My first approach was to find out the dimensions of the Art box, media box, trim box, crop box; and try to figure out if any of these boxes didn't include the white space, so i could just crop that out and save as a new PDF.

However this PDF doesn't have the ArtBox/TrimBox correctly set. So i can't take this approach.

My Next though was to manually crop the PDF with respect to the printer/crop marks at the edges. However I'm unable to locate these elements inside the PDF using Aspose.

Upvotes: 1

Views: 1873

Answers (2)

Saqib Razzaq
Saqib Razzaq

Reputation: 1430

The below Aspose.Pdf for .NET example will crop your PDF and remove the printer marks.

Aspose.Pdf.Document document = new Aspose.Pdf.Document(dataDir + "bre25419_cover.pdf");
//Iterate through All Pages of a PDF Document
for (int i = 1; i <= document.Pages.Count; i++)
{
    Aspose.Pdf.Rectangle cropBox = document.Pages[i].CropBox;
    // Crop percentage of width and height
    double percentageX = 4.4f / 100 * cropBox.URX;
    double percentageY = 6.7f / 100 * cropBox.URY;
    // update page's crop box
    document.Pages[i].CropBox = new Aspose.Pdf.Rectangle(cropBox.LLX + percentageX, cropBox.LLY + percentageY, cropBox.URX - percentageX, cropBox.URY - percentageY);

    Console.WriteLine("cropBox.LLX: " + cropBox.LLX + "\ncropBox.LLY: " + cropBox.LLY + "\ncropBox.URX: " + cropBox.URX + "\ncropBox.URY: " + cropBox.URY);
}
// save document         
document.Save(dataDir + "bre25419_cover_Output.pdf");

I work as a Developer Evangelist at Aspose.

Upvotes: 1

stanlyF
stanlyF

Reputation: 266

In your specific case TrimBox == ArtBox == BleedBox == MediaBox [0 0 1642.5 1035]. There is no CropBox, so you can try to change MediaBox values,it used instead of CropBox by default (say with help of iText).

I have changed MediaBox a bit [72 72 1570.5 963]: enter image description here

Upvotes: 1

Related Questions