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?

Posted on Nov 25, 2017 12:02 AM

Reply
4 replies

Nov 27, 2017 1:36 PM in response to Flashx

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 number of pages per extracted PDF (pick any number, defaults to 3)
  • Input PDF
  • output folder


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.

User uploaded file

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.

  1. Utilities : Run Shell Script (In Sierra and later, this is Automator : Run Shell Script).

    Set the shell to /bin/bash, and Pass input: as arguments. Replace entire default content with Code A below.

  2. Text : Ask for Text
    1. How many pages per each PDF extraction? Default it to 3. Require an answer.
    2. Click the Options, and check "Ignore this actions input" so output of the preceding action does not interfere.
  3. Utilities : Set Value of Variable

    In the selector, click New Variable, and name it maxpage

  4. Files & Folders : Ask for Finder Items

    Take the defaults, and for Type, select Files. Do not allow multiple selection.

  5. Files & Folders : Filter Finder Items

    All of the following are true Kind is PDF

  6. Files & Folders : Ask for Finder Items

    Take the defaults, but now set Type to Folders. Do not allow multiple selection.

  7. Utilities : Get Value of Variable

    in the selector, click maxpage

  8. Right now, the order of variables that are about to flow into the last action are: pdfFolder, outFolder, and maxpage.
  9. Run Shell Script based on the first Item 1 above.
    1. Set the shell to /bin/bash, and the Pass input to as arguments to receive items from 8.
    2. Replace entire default content of Run Shell Script action with Code B below.
  10. Save the Automator application to your Desktop as (e.g. extPDF.app) and you can hide the extension).
  11. Quit Automator. You are done, and can start extracting PDF pages.


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

Nov 26, 2017 5:19 PM in response to Flashx

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.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Automator - Splitting PDF files

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.