Skip to content

Instantly share code, notes, and snippets.

@pointybeard
Last active July 29, 2021 00:08
Show Gist options
  • Save pointybeard/88b50a6ddc888bf899544dd7697a258a to your computer and use it in GitHub Desktop.
Save pointybeard/88b50a6ddc888bf899544dd7697a258a to your computer and use it in GitHub Desktop.
How to get PDF page dimensions in MM from CLI

How to get PDF page dimensions in MM

Using pdfinfo

apt install poppler-utils

Then, use the following command:

pdfinfo test.pdf | grep "Page size" | grep -Eo '[-+]?[0-9]*\.?[0-9]+' | awk -v x=0.3528 '{print $1*x}'

Using ImageMagick

apt install imagemagick

nano /etc/ImageMagick-6/policy.xml

Add <policy domain="coder" rights="read | write" pattern="PDF" /> to end of <policymap> element (comment out existing PDF line).

Finally, use the following command:

identify -verbose test.pdf  | grep "Print size" | grep -Eo '[-+]?[0-9]*\.?[0-9]+' | awk -v x=25.4 '{print $1*x}'

Acknowledgements

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment