The subject might sound odd, but here’s why I’m needing to do this. I am batch generating PDF files from Filemaker Pro 14. The resulting PDFs open fine in Preview, but not with Acrobat Reader/Pro (resulting error “An error exists on this page. Acrobat may not display the page correctly. Please contact the person who created the PDF document to correct the problem.”). This is a known Filemaker bug (http://forums.filemaker.com/posts/43f4da4247). Unfortunately, my end users don’t use Macs or Preview, so the files need to behave properly with Acrobat.
I have discovered that one way round this problem is to open each PDF in Preview, then “Export as PDF” with the same file name to overwrite original file. The files so generated can be opened without error messages in Acrobat. As I may be generating several hundred PDFs at a time this way, I’m looking for a way to automate the opening of the PDFs and Export as PDF by Preview. I have perused the discussion groups a little, and tried a few things with Automator/Applescript, but I have very little experience with these tools. The resulting converted files could either replace the originals or populate another folder so the originals are preserved. Can anyone help?
Much appreciated.
Richard
Mac 10.10.5, Preview 8.0, Filemaker Pro Advanced 14
iMac (Retina 5K, 27-inch, Late 2014), OS X Yosemite (10.10.5)
Try saving this as an application, and drag the PDFs over it:
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "Quartz"
on open fileList -- drag list of PDFs to be updated
repeat with aFile in fileList
set theURL to (current application's class "NSURL"'s fileURLWithPath:(POSIX path of aFile))
set newName to (theURL's lastPathComponent()'s stringByDeletingPathExtension()'s stringByAppendingString:"+")
set newURL to ((theURL's URLByDeletingLastPathComponent()'s URLByAppendingPathComponent:newName)'s URLByAppendingPathExtension:"pdf")
set thePDFDoc to (current application's PDFDocument's alloc()'s initWithURL:theURL)
(thisPDFDoc's writeToURL:newURL)
end repeat
display dialog "Finished" buttons {"OK"}
end open
When I run PDFs over the app, I get the error “The variable posixPath is not defined. (-2753)”. But, if I read your script correctly (and theres’ a good chance I’m wrong!) it will basically add a “.pdf” extension to each file after removing it first? I don’t think that will do what I need, which is for each PDF to be opened by the Preview app, and from there Exported as a PDF. There’s some “magic” in that process that then makes the PDFs open in Acrobat without error. I’ve manually tried deleting and then adding back the extension .pdf, but it makes no difference.
Hello Richard and Shane
I stumbled upon this (old) thread while searching a way to script Preview app to save PDF/A.
Originally, my problem was related to a PDF generated by Ghostscript (no hand on that). While Preview in macOS 13 (Ventura) or 14 (Sonoma) shows everything at the right place on the page, Adobe Reader 2025 misses displaying some text with a Type 3 font…
I found that saving as PDF/A in Preview, and opening that PDF/A in Adobe Reader make the missing text reappearing correctly.
I haven’t found yet a good script to do that precisely, but when I read Shane’s script I wanted to give it a try. And consequently signing in macscripter.net !
And… I too run against -2753 error, BUT with a major hint !
“the variable thisPDFDoc is not defined. (-2753)” thisPDFDoc must be thePDFDoc !
So, Shane, I just corrected your typo, and the script works perfectly !
On top of that, it solved my problem ! No need to save as PDF/A specifically, just saving it as std PDF again make Adobe Reader render correctly all the text in the PDF !
Thanks a lot !
This could help others.
Raffi