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}'
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}'