For scripting I need to get the page dimensions of a PDF file (in mm).

pdfinfo just prints it in 'pts', e.g.:

Page size:      624 x 312 pts

What should I use?

Or what unit is 'pts' anyway - in case I want to convert them ...

  • 2
    Point on Wikipedia – Mat May 27 '12 at 18:16
  • Which page did you want the size of? The legal size outer cover? The leaflet size "this page is intentionally blank"? The letter size double pages? – Ignacio Vazquez-Abrams May 28 '12 at 9:53
up vote 24 down vote accepted

The 'pts' unit used by pdfinfo denotes a PostScript point. A PostScript point is defined in terms of an inch and a resolution of 72 dots per inch:

In the late 1980s to the 1990s, the traditional point was supplanted by the desktop publishing point (also called the PostScript point), which was defined as 72 points to the inch (1 point = 1⁄72 inches = 25.4⁄72 mm = 0.352¯7 mm [ ≙ 0.3528 mm] ).

The manual to gv contains a list of common paper formats specified in PostScript points.

  • 1
    on common paper formats: pdfinfo sometimes gives me the paper format (like Page size: 595.28 x 841.89 pts (A4)) — I wonder if it does that for a list of page sizes it knows about? – njsg May 27 '12 at 20:45
  • 2
    A point is actually 0.352777777... mm, so 0.3528 mm is a closer approximation. – cjm May 28 '12 at 5:34

Not the easiest way, but given imagemagick and units you could also use

$ identify -verbose some.pdf | grep "Print size" 
Print size: 8.26389x11.6944

to find the page size in inches (this may yield several results if the PDF uses different dimensions) and then convert the numbers like this:

$ units -t '8.26389 inch' 'mm'

Meaning that 8.26 inches are 209.9 mm (I used an A4 PDF for this).

  • 1
    When I identify a PDF on OS X I don't get any output. – David Moles May 31 '16 at 20:58

Came across the same problem and came to the following solution. I didn't get into the documentation of how pdf files are constructed I just compared two empty pdf files with different page sizes.

It looks like pdfs have all kinds of attributes embedded between "<<" and ">>". I found that the page size info is there in plain text and can be found with a simple regex search.

This may or may not be true to all pdfs but it worked on all I could find from different sources.

The relevant part can look like any of these for a size A4 page:

/MediaBox [0 0 595 842]
/MediaBox[0 0 595 842]
/MediaBox[ 0 0 595.32 841.92]

It means [0 0 width height] so here is my super lame but working solution to extract this:

cat test.pdf | egrep -ao "/MediaBox ?\[ ?[0-9]+ [0-9]+ [0-9]+(\.[0-9]+)? [0-9]+(\.[0-9]+)?\]" | head -1

Just change test.pdf to your file.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.