How to crop or change the page size of a existing PDF file

Discussions about PDF management.
Post Reply
vega68
Posts: 5
Joined: Wed Aug 04, 2010 4:11 pm

How to crop or change the page size of a existing PDF file

Post by vega68 » Thu Jul 12, 2018 2:02 pm

Hello,

how can I change the page size of an existing PDF files from e. g. 7x7 inches to a page size with 4x4 inches?
There is no information outside the top/left area with 4x4 inches.

We have a special application for this type of PDF files and therefore it is extremely important that they have the exactly predefined size.

I've already tried to crop the PDF file page by setting the page height and width but then I will loose the information in the top area instead of the area at the bottom.

I seems to be a problem with the originally used coordinate system in the PDF file.

Example with 7x7 (x -> information, _ -> no information):
xxxx___
xxxx___
xxxx___
xxxx___
_______
_______
_______

should be 4x4:
xxxx
xxxx
xxxx
xxxx

What I get after my "cropping" to 4x4:
xxxx___
_______
_______
_______



Kind regards,

vega68

Matus
Posts: 9
Joined: Tue Jan 15, 2019 1:00 pm

Re: How to crop or change the page size of a existing PDF file

Post by Matus » Tue Jan 15, 2019 1:34 pm

Hello,

I order to achieve this you need to use the SetPageBox method.
Link here:
https://www.gdpicture.com/guides/gdpicture/web ... geBox.html

To get correct PageBox parameters you need to know that PageBox in PDF is always using BottomLeft coordinates.
This means that in your case you just need to make use of GetPageHeight to calculate correct Top and Bottom parameters.
Use following call to set 4x4 inch CropBox on selected page.

Code: Select all

status = oGdPicturePDF.SetPageBox(PdfPageBox.PdfPageBoxCropBox, 0, oGdPicturePDF.GetPageHeight(), 4, oGdPicturePDF.GetPageHeight()-4);

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests