Wednesday, March 25, 2009

pdfinfo in centimeters

pdfinfo is one of the utility programs bundled with xpdf that gives useful information about PDF files, including its size. However, the size is written in Postscript points, and I can't say I'm that fluent in this unit to actually know how big that is. So here is a shell function that converts the output of pdfinfo into centimeters. Enjoy !

pdfinfom () {
    pdfinfo "$@" | perl -p -e \
 's#(\d+)\s*x\s*(\d+)\s*pts#(sprintf "%.2f", ($1*2.54/72))." x ".(sprintf "%.2f", ($2*2.54/72))." cm"#e'
}

2 comments:

aNOnimous said...

Hi!
I adapted the function to optionally accept decimal dimensions (e.g. 725.7 x 1091.4 pts) that my system uses. (Ubuntu 12.10, pdfinfo v0.20.4 from package poppler-utils).
Take care


pdfinfom () { pdfinfo "$@" | perl -p -e 's#(\d+\.*\d*)\s*x\s*(\d+\.*\d*)\s*pts#(sprintf "%.2f", ($1*2.54/72))." x ".(sprintf "%.2f", ($2*2.54/72))." cm"#e'; };

aNOnimous said...

Hi!
I twiked your nice function to optionally accept decimal dimensions (e.g. 725.7 x 1091.4 pts), as found on my system. (Ubuntu 12.10, pdfinfo 0.20.4 from package poppler-utils ).
Take care


pdfinfom () { pdfinfo "$@" | perl -p -e 's#(\d+\.*\d*)\s*x\s*(\d+\.*\d*)\s*pts#(sprintf "%.2f", ($1*2.54/72))." x ".(sprintf "%.2f", ($2*2.54/72))." cm"#e'; };