I want to convert a pdf with several pages to single image files using sips. I know there are several other (probably better) solutions to do this but sips is installed on every mac and don't need a licence.
What I tried:
sips -s format png myPDF.pdf --out myIMG.png
That gives me an image of the first site from the pdf.
Now my Question: Is there a possibility to get images for each page of the pdf?
Thanks for your advise!
I have no idea whether you are supposed to do this sort of thing this way, but the Automator on macOS has an action called Split PDF
which you could use to split a PDF into separate pages and then use sips
on each one...
To start Automator, press ⌘space and start typing Automator
till it guesses correctly and hit ↩. This is called a Spotlight Search apparently and is the quickest way to find anything on a Mac but no-one tells you that!
Then create a new Application, and select PDFs
on the left (highlighted in red), then Split PDF
(also in red) and drag that into the "work-area" on the right.
I saved that then as splitter
.
Then I started Terminal - same Spotlight Search method as starting Automator above, but start typing Terminal
instead.
Now go to where you saved splitter
and you'll see splitter.app
:
ls -ld splitter*
drwxr-xr-x@ 3 mark staff 96 27 Nov 12:09 splitter.app
Now I want to split a 10-page document called "a.pdf"
, so I ran:
echo "a.pdf" | automator -i - ./splitter.app
Sample Output
2018-11-27 12:15:21.200 automator[24004:3655998] Cache location entry for /Applications/Photos.app in cache file at /Users/mark/Library/Caches/com.apple.automator.actionCache-bundleLocations.plist is not valid: (null)
(
"/Users/mark/Desktop/a-page1.pdf",
"/Users/mark/Desktop/a-page2.pdf",
"/Users/mark/Desktop/a-page3.pdf",
"/Users/mark/Desktop/a-page4.pdf",
"/Users/mark/Desktop/a-page5.pdf",
"/Users/mark/Desktop/a-page6.pdf",
"/Users/mark/Desktop/a-page7.pdf",
"/Users/mark/Desktop/a-page8.pdf",
"/Users/mark/Desktop/a-page9.pdf",
"/Users/mark/Desktop/a-page10.pdf"
)
And it spits out 10 separate 1-page PDF documents on my desktop named per the output.
I have no idea what the warning about "Photos App" cache file means, so if anyone knows, maybe they would tell me what it means and how to get rid of it.
Also, I presume that Automator is somehow calling the action from /System/Library/Automator/Split PDF.action
:
file "/System/Library/Automator/Split PDF.action/Contents/MacOS/Split PDF"
/System/Library/Automator/Split PDF.action/Contents/MacOS/Split PDF: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit bundle x86_64] [i386:Mach-O bundle i386]
/System/Library/Automator/Split PDF.action/Contents/MacOS/Split PDF (for architecture x86_64): Mach-O 64-bit bundle x86_64
/System/Library/Automator/Split PDF.action/Contents/MacOS/Split PDF (for architecture i386): Mach-O bundle i386
But, I have no idea how I can execute/call that from Terminal, without needing to start/write any Automator stuff. So, if anyone, @vadian maybe, knows, I would love to know that too! It appears to be a bundle, but if I run mdls
on it, there is no bundle identifier listed, so I cannot run it with:
open -b <BUNDLE-IDENTIFIER>