Batch Exporting pdfs in Preview

Hi, I have lots of pdfs containing scans/photos of receipts. The OCRd Text is not embedded yet.


I just learned it's easy to do that via "Export..." in the Preview app. If Preview recognizes that a pdf does not have text embedded yet, it shows a checkbox "Embed Text".


(Embed text in a PDF - Apple Support (IS))


This is great! Does anybody know of a Shortcut or AppleScript action that allows me to batch process a large number pdfs in this way?


Best, Geb


Posted on Mar 5, 2025 4:55 AM

Reply
6 replies

Mar 5, 2025 8:49 AM in response to Gebhard Sengmüller

The AppleScript support for Preview is abysmal and there is no reserved AppleScript verb to open the Export panel.


Back in the Summer of 2023, I wrote a GUI AppleScript solution for Preview that forced the Export panel to open, enter a custom Finder tag, change the output filename to append "_PDFA", click the PDF/A, and Linearize the PDF check boxes before saving the PDF. Still works in macOS Sequoia v15.3.1.


The caveat with GUI scripting is that with any future release of macOS, Apple can alter the Preview application's internal framework structure and break the GUI scripting code. If this happens, I am unlikely to fix it due to time constraints.


I don't have macOS Ventura installed, so cannot say if its Preview has an Export panel Embed Text checkbox. I have noticed the Embed Text check box is not available for a scanned PDF in Big Sur or Monterey operating systems. In Sonoma 14.7.4, only the Embed Text checkbox is present, and with Sequoia v15.3.1, all check boxes that you showed in your post are available.


I modified my 2023 AppleScript by commenting out the previous Finder Tag, PDF/A, and Linearize check box settings, but do append "_ocr" to the PDF basename on this panel. It checks if the operating system version is 14 and will only select Embed Text, or select all three check boxes if in Sequoia.


This is currently not a batch solution as it only prompts for a single PDF. If that PDF is scanned, and hence contains no fonts, processing will continue. Otherwise, the script will quit as it would be a different Export panel for regular PDF documents. It may take a fair amount of work to make this into a batch solution such as a Shortcut Quick Action that accepts a single PDF or a folder of scanned PDFs.


In the Finder, press shift+cmd+U to open the Utility folder and then double-click Script Editor to launch it. Then copy/paste the following AppleScript code into the Script Editor, click compile and run to select your scanned PDF. The script will write the OCR'd PDF into the same filesystem location. I have confirmed that the PDF search works afterward.


Although I am in the U.S., I tested this with scanned German text.



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.

Batch Exporting pdfs in Preview

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