Looking for any method to quickly flatten a PDF without opening Preview and without installing 3 party software. Any ideas?
Save as PDF in Preview works, but I don't want to have to open Preview each time I need to do this.
The Create PDF action which appears in Finder when you select 2 or more PDFs flattens PDFs, but it requires me to select 2 or more files, and I generally don't want to combine PDFs--I simply wish to flatten a PDF.
Most Automator and Shortcuts options I am aware of do not flatten PDFs, and in some cases, strip out form field data from PDFs.
Yes, you will need to use Xcode for developing any of these solutions. You can download that from inside your account on developer.apple.com or from the App Store.
Since you're asking that particular question, I think it's reasonable to assume you haven't been doing much macOS development recently so I think it would be good to start with the most direct route. I suggest writing a command line tool and then, if you want to use it from AppleScript use the do shell script
command.
For more information about do shell script
see this document:
Technical Note TN2065: do shell script in AppleScript
For reading and writing PDF documents, see the Read Operations and Write Operations listed for the PDFDocument class. There are a number of APIs you can use there. Some allow specifying options. To flatten the PDF, specify the burnInAnnotationsOption when you save the PDFDocument.
I think that should be enough to get you started on a very direct and easy to implement solution. If you'd like to talk about other solutions, let me know. There is some older documentation about making AppleScript apps, or Automator additions, in the Documentation Archive.