Search code examples
macospdfapplescript

How can I programmatically rotate all the pages in a PDF using native macOS tools?


Given a file path, I need to rotate all the pages in a PDF at that file path using nothing that isn't included with macOS. The wrapper for this will be AppleScript, so I also have access to the command line and therefore all of the scripting languages installed by default with macOS, but nothing that would require brew or, for example, Python's pip.


Solution

  • Here's the solution I used.

    • Automator to separate the PDF into individual pages in a new folder at the same level as the original PDF
    • Some AppleScript to rotate a single page PDF using Image Events
    • A second Automator workflow to stitch the separate PDFs back together again
    • An AppleScript that controls everything, using do shell script to open each of the Automator workflows as needed.