Page 1 of 1

Get exact PDF size with identify

Posted: 2010-08-22T12:55:51-07:00
by Monarobase
Hello,

I've been trying to get the exact size of a PDF document without success.

My test document is A4 (210mm x 297mm) which is 595.28pt x 841.89pt.

When I do :

Code: Select all

identify -format "%[fx:w]x%[fx:h]" testpdf.pdf
I get :

Code: Select all

595x842
If I do :

Code: Select all

identify -format "%@" testpdf.pdf 
I get :

Code: Select all

342x54+133+239
And when I do :

Code: Select all

identify -verbose testpdf.pdf
There is a section with :

Code: Select all

Properties:
    create-date: 2010-08-22T19:02:05+00:00
    modify-date: 2010-08-22T19:02:05+00:00
    pdf:HiResBoundingBox: 595.28x841.89+0+0
    pdf:Version: PDF-1.3
    signature: bb3128cf288b1737dc3a29250cef1da8cb14302dd4e9e7f75c47901d77b62f83
If I convert 595 to mm I get 209.9mm but if I convert 596.28 I get 210mm

I need to be able to upload my PDF document and automatically get the exact PDF size. Can I get the HiResBoundingBox value using identify ?

Thank you !

Re: Get exact PDF size with identify

Posted: 2010-08-22T13:21:21-07:00
by fmw42
I don't believe that PDF files have a unique pixel size as they are vector format. They are controlled by the density you assign to them when you convert to some raster format. However, any pictures contained in the PDF will have their own size.

Re: Get exact PDF size with identify

Posted: 2010-08-22T19:38:06-07:00
by Drarakel
You should be able to retrieve the exact "HiResBoundingBox" value (which is the MediaBox value in PDF) with:

Code: Select all

identify -format "%[pdf:HiResBoundingBox]" testpdf.pdf

Re: Get exact PDF size with identify

Posted: 2010-08-23T01:26:20-07:00
by Monarobase
Thanks - Works great !