Extract Images from PDF according to TrimBox

I have a PDF file which contains one bitmap image per page. The pages of the file have been cropped using Adobe Acrobat. As always with Adobe Acrobat, the PDF file still contains the full original bitmaps, but the TrimBox coordinates indicate the part of the bitmaps that are shown when viewing the PDF.


I’d like to use Aspose.PDF to extract the visible parts of the bitmaps. However, when I extract the bitmaps using Aspose.PDF, I receive the full bitmaps. How can I instruct Aspose.PDF to first crop the bitmaps according to the TrimBox?

Hi there,

Thanks for your inquiry. I think you can accomplish your requirement in two steps. Initially crop the PDF page by setting CropBox coordinates as per TrimBox coordinates and later convert it to Image. Hopefully it will serve the purpose.

Moreover, please note point is measuring unit in Aspose.Pdf and 72 points=1 inch.

Document document = new Document(myDir+“Input.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;
// update page’s crop box
document.Pages[i].CropBox = new Aspose.Pdf.Rectangle(cropBox.LLX + 72, cropBox.LLY + 72, cropBox.URX - 72, cropBox.URY - 72);
}
// save document
document.Save(myDir+“Output.pdf”);

Please feel free to contact us for any further assistance.

Best Regards,