The issue in this thread is that the Automator Render PDF pages as images action does not flatten PDF, and thus, excludes any PDF annotation in the resulting images. The second issue is that the Apple Preview AppleScript dictionary support does not allow saving flattened PDFs. The goal here is to use available Apple technology to get this done in a practical workflow.
It is possible to save a flattened PDF using AppleScript/Objective-C using features from a few Apple frameworks and programmatically printing that annotated PDF to a file, instead of to the printer. This simulates the Print panel's PDF > Save As PDF feature. Here is that code that when pasted into the Script Editor, compiled, and ran, prompts for a PDF and then saves as that pdfname_flattened.pdf in the original PDF location:
use framework "Foundation"
use framework "AppKit"
use framework "PDFKit"
use AppleScript version "2.4"
use scripting additions
property SUFFIX : "_flattened"
property NSString : a reference to current application's NSString
property NSURL : a reference to current application's NSURL
property PDFDocument : a reference to current application's PDFDocument
property NSDictionary : a reference to current application's NSDictionary
property NSPrintInfo : a reference to current application's NSPrintInfo
set thisPDF to POSIX path of (choose file of type "com.adobe.pdf" default location (path to desktop) without invisibles) as text
set {status, flatPDF} to my flatten_PDF(thisPDF)
if status = true then
display dialog "Flattened PDF created" & return & return & flatPDF with title "Print Operation Results"
else
display dialog "Flattened PDF operation failed." with title "Print Operation Results"
end if
return
on flatten_PDF(thisPDF)
set basename to (NSString's stringWithString:thisPDF)'s stringByDeletingPathExtension()
set basename_sfx to basename's stringByAppendingString:SUFFIX
set outPDF to basename_sfx's stringByAppendingPathExtension:"pdf"
set outURL to NSURL's fileURLWithPath:outPDF
set inURL to NSURL's fileURLWithPath:thisPDF
set pdf to PDFDocument's alloc()'s initWithURL:inURL
# make assumption that first page of PDF has same MediaBox as rest of the PDF
set {{x, y}, {w, h}} to (pdf's pageAtIndex:0)'s boundsForBox:(current application's kPDFDisplayBoxMediaBox)
set pdict to (NSDictionary's dictionaryWithObject:outURL forKey:(current application's NSPrintJobSavingURL))'s mutableCopy()
pdict's setObject:(current application's NSPrintSaveJob) forKey:(current application's NSPrintJobDisposition)
pdict's setObject:outURL forKey:(current application's NSPrintJobSavingURL)
set printInfo to NSPrintInfo's alloc()'s initWithDictionary:pdict
printInfo's setVerticalPagination:(current application's NSPrintingPaginationModeAutomatic)
printInfo's setJobDisposition:(current application's NSPrintSaveJob)
printInfo's setPaperSize:(current application's NSMakeSize(w, h))
set printOp to pdf's printOperationForPrintInfo:printInfo scalingMode:0 autoRotate:false
printOp's setShowsPrintPanel:false
printOp's setShowsProgressPanel:false
set status to printOp's runOperation()
return {status as boolean, (outPDF's stringByAbbreviatingWithTildeInPath()) as text}
end flatten_PDF
Now, based on the OPs situation, how to incorporate this PDF flattening process prior to the Render PDF Pages as Images Automator action and pass the flattened PDF into that action. Here is that Automator workflow in sequential actions:
Automator actions (in order) for an Automator Application:
- Files & Folders : Ask for Finder Items
- Start At: Desktop
- Type: Files ☐ Allow multiple selection
- Files & Folders: Filter Finder Items
- All Kind is PDF
- Utilities: Run AppleScript
- Remove all of the default content, and replace with the code show below that you copy/paste into this action
- Passes the path of the flattened PDF into next action
- PDF: Render PDF Pages as Images
- Choose these settings to your goal
- Files & Folders: Rename Finder Items
- Add the copy finder items when asked
- Set to the destination folder for your images
- Rename Finder Items
- Make Sequential
- Add number to existing item name
- Place number after name and start numbers at 1
- Separated by underscore and make all numbers 2 (or 3) digits long (eg. someimage_01.jpg)
- This action does not operate as it suggests. Instead of someimage_01.jpg, it will create someimage 1_1.jpg instead. No fix for this if using sequential numbering.
- Save to Desktop and Quit Automator
Code for 3.1 (exceeded 5000 characters, see Reply to this post for code to paste into Run AppleScript action.