We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Crop pdf page to its bounding box

How can I crop a pdf page to its bounding box, i.e. the smallest rectangle that includes all text and objects on a pdf page?

Thanks,
Bernhard

Hi Bernhard,


Thanks for contacting support.

As per my understanding, you need to eliminate the white space around contents of PDF file. If the PDF file only contains Text, then you can get reference of individual PDF page, start searching all page contents and get X,Y position of first TextFragment over PDF page, get X,Y coordinates of last TextFragment over page, and then use same values to remove margin around PDF file.

However if the PDF file contains contents other than Text, then you may consider using the approach specified over Trim White-space Around a Page (currently the code is available for .NET but you can get the idea to create similar code for your requirements).

You may also consider visiting following links for further details on

Many thanks for the quick response.

Rendering the image to a bitmap to find it’s bounding box! Looks like pdf is more rendering than description - despite it’s name.

I’ll continue to rely on pdfcrop for this function.

Thanks,
Bernhard

Hi Bernhard,


I am afraid I am unable to understand your query. Can you please elaborate it so we may reply accordingly.

What I meant is that I use a different program for this step. The programming you suggest is beyond my abilities.

Hi Bernhard,


Aspose.Pdf is PDF creation / manipulation API and in order to determine the white space around page contents, we need to try using Bitmap objects so that we can determine the start point of elements inside image (which generated from PDF document). Should you have any further query, please feel free to contact.