Automator - Splitting PDF files
hi guys,
how would i go about setting up automator to take a 40 page doc file and spitting it up into pdf files?
I am wanting the pattern of pg 1,2,3 then 4,5,6, then 7,8,9 etc saved out as pdfs.
any ideas?
hi guys,
how would i go about setting up automator to take a 40 page doc file and spitting it up into pdf files?
I am wanting the pattern of pg 1,2,3 then 4,5,6, then 7,8,9 etc saved out as pdfs.
any ideas?
Download and install the Skim application, if you haven't already done so. The Automator application that I have constructed will require it to perform the PDF extractions. If you have no intention of downloading Skim, then stop reading now.
Installation of Skim is simplistic. You drag the application over the Application folder alias in the installer. Then you eject the installer. You must then right-click on the /Applications/Skim.app and select open to complete the installation process. Quit Skim. This is a one-time ritual since it did not come from the Mac App Store.
The Automator application will prompt you for three things:
The Automator application will check to see if Skim is installed, and will dialog you, and fail if it is not installed.
It will name the output files based on the name of the original input PDF (in this example tim40.pdf, and 3 pages), and will include the page range included in the extracted PDF as part of the name. This works for any specified page count less than the number of pages in the original PDF.
So, let's build the Automator application. Start with the Dock : Launchpad : Other : Automator.
If you receive a prompt, select the Application icon, and then click Choose. If not, then select File menu : New, and then follow the first sentence. The left of the Automator screen that now appears will reflect categorical Libraries — each containing relevant actions that can be dragged and dropped in appropriate order into the large right-hand workflow window. This will be the application flow.
Here is the list of Libraries, and their actions that you will drag/drop (in order) to the right workflow window.
Set the shell to /bin/bash, and Pass input: as arguments. Replace entire default content with Code A below.
In the selector, click New Variable, and name it maxpage
Take the defaults, and for Type, select Files. Do not allow multiple selection.
All of the following are true Kind is PDF
Take the defaults, but now set Type to Folders. Do not allow multiple selection.
in the selector, click maxpage
Code A (scrollable, so select all of it)
#!/bin/bash SKIMPDF="/Applications/Skim.app/Contents/SharedSupport/skimpdf" usage () { ( osascript <<-AS display alert "This Skim application is not installed. Automator is quitting." as critical giving up after 10 return AS ) } # check if skim application is installed, and if not warn/quit [[ ! -x $SKIMPDF ]] && usage && exit 1 exit 0
Code B (scrollable, so select all of it)
#!/bin/bash SKIMPDF="/Applications/Skim.app/Contents/SharedSupport/skimpdf" # Try to make let more POSIX compliant, which the Bash built-in let is not let () { IFS=, command eval test '$(($*))' -ne 0 } # set these variables from the command-line arguments read -r pdfFile outFolder maxpage <<< "$@" # extract the pdfFile basename from the path and extension and add underscore shopt -s extglob outPDFbase="${pdfFile//+(*\/|.*)}""_" shopt -u extglob pagecnt=$(mdls -name kMDItemNumberOfPages "${pdfFile}" | egrep -o "([[:digit:]]+)") [[ $maxpage -ge $pagecnt ]] && let maxpage=3 # change this to control number of extracted pages per output PDF file let p3=$maxpage page_range="" for ((i = 1; i <= $pagecnt; i+=$maxpage)) do # are we within the pagecnt range, then reflect the page_range if [ $(($i + $maxpage)) -le $pagecnt ]; then page_range=$i"_"$(($i + $maxpage - 1)) # Is the pagecnt same or less than our increment, then set ending page elif [ $pagecnt -le $maxpage ]; then page_range=$i"_"$pagecnt let p3=$pagecnt # get the remaining orphan pages less than the maxpage count else page_range=$i"_"$pagecnt let "p3 = 1 + $pagecnt % i" fi $SKIMPDF extract "${pdfFile}" "$outFolder""/""$outPDFbase""$page_range".pdf -range $i $p3 done exit 0
The term “latest” has been found to be incorrect in these support communities on more occasions than you can imagine. Please provide the explicit version of the operating system, as that will avoid any guess work.
Automator does not provide a means to split a Word .doc file into increasing page triplets that are then exported to PDF. This will require custom programming. What specific application (and explicit version of it) do you presently use to open that Word document?
An alternative would be to export that .doc file to a single PDF, and then use PDFKit, or the command-line version of the Skim application to extract page ranges to PDF.
On what Mac with what operating system?
Hi Klaus1,
Im using the latest Mac sierra.
🙂
Automator - Splitting PDF files