Get exact PDF size with identify

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Monarobase
Posts: 4
Joined: 2010-06-25T06:26:13-07:00
Authentication code: 8675308

Get exact PDF size with identify

Post 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 !
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Get exact PDF size with identify

Post 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.
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: Get exact PDF size with identify

Post 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
Monarobase
Posts: 4
Joined: 2010-06-25T06:26:13-07:00
Authentication code: 8675308

Re: Get exact PDF size with identify

Post by Monarobase »

Thanks - Works great !
Post Reply