How can I totally flatten a PDF in Mac OS on the command line?
- by Matthew Leingang
I use Mac OS X Snow Leopard. I have a PDF with form fields, annotations, and stamps on it. I would like to freeze (or "flatten") that PDF so that the form fields can't be changed and the annotations/stamps are no longer editable. Since I actually have many of these PDFs, I want to do this automatically on the command line.
Some things I've tried/considered, with their degree of success:
Open in Preview and Print to File. This creates a totally flat PDF without changing the file size. The only way to automate seems to be to write a kludgy UI-based AppleScript, though, which I've been trying to avoid.
Open in Acrobat Pro and use a JavaScript function to flatten. Again, not sure how to automate this on the command line.
Use pdftk with the flatten option. But this only flattens form fields, not stamps and other annotations.
Use cupsfilter which can create PDF from many file formats. Like pdftk this flattened only the form fields.
Use cups-pdf to hook into the Mac's printserver and save a PDF file instead of print. I used the macports version. The resulting file is flat but huge. I tried this on an 8MB file; the flattened PDF was 358MB! Perhaps this can be combined with a ghostscript call as in Ubuntu Tip:Howto reduce PDF file size from command line.
Any other suggestions would be appreciated.