Identify if a PDF is landscape or portrait

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Identify if a PDF is landscape or portrait Tue Jan 01, 2019 7:02 am • by Robert
Happy New Year to all of you,
I have a question I could not find an answer to in the forum. Is there a possibility to identify the orientation of a PDF file? I have about 2000 PDFs and a lot of them are scanned double pages (so landscape) PDFs. These I want to process further to split the double pages with Abby FineReader, as this OCR software is doing this automatically.
There is a way to do that with pictures – but this does not work with the PDFs I tried. So I thought I could determine if the width is greater than the hight sort of thing, but Hazel does not offer that (as far as I can see).
Maybe someone knows an apple script or shell script which can do that?
That would be wonderful!
"Behind all the inhuman aspects of automation (...) its real possibilities appear: the genesis of a technological world in which man can finally withdraw from (...) the apparatus of his labor – in order to experiment freely with it." /Marcuse
Robert
 
Posts: 52
Joined: Sun Dec 16, 2018 8:05 am

Re: Identify if a PDF is landscape or portrait Wed Jan 02, 2019 5:43 am • by Robert
The user Olivetti from MacUser.de https://www.macuser.de/threads/orientierung-eines-pdfs-identifizieren-applescript-bash-hazel.816701/#post-10019083 helped me, finding a way to identify landscape PDFs.

All you need are the Xpdf tools: http://www.xpdfreader.com/download.html

The File passes the Shellscript:

With consideration of the rotation:
Code: Select all
#!/bin/bash
ps=$(pdfinfo "$1" | grep 'Page size')
x=$(echo "${ps}" | awk {'print $3'})
y=$(echo "${ps}" | awk {'print $5'})
r=$(echo "${ps}" | grep -o 'rotated.*' | awk '{print $2}')

export LC_ALL=C
x=$(printf "%.0f" "${x}")
y=$(printf "%.0f" "${y}")

[[ "${r}" -eq "0" ]] && [[ "${x}" -lt "${y}" ]] && exit 1 || exit 0


Without consideration of PDF rotation:
Code: Select all
 
#!/bin/bash
ps=$(pdfinfo "$1" | grep 'Page size')
x=$(echo "${ps}" | awk {'print $3'})
y=$(echo "${ps}" | awk {'print $5'})

export LC_ALL=C
x=$(printf "%.0f" "${x}")
y=$(printf "%.0f" "${y}")

[[ "${x}" -lt "${y}" ]] && exit 1 || exit 0


Works great for me!
"Behind all the inhuman aspects of automation (...) its real possibilities appear: the genesis of a technological world in which man can finally withdraw from (...) the apparatus of his labor – in order to experiment freely with it." /Marcuse
Robert
 
Posts: 52
Joined: Sun Dec 16, 2018 8:05 am


Return to Support