Save a PDF file as a TIFF with Acrobat 8.0, AppleScript & JavaScript.

I am hoping someone can help me out with my syntax issue.
I have been working on creating a droplet that would create a TIFF from a PDF. We get a lot of client supplied PDFs that we drop into our templates. Our printer would like us to furnish a TIFF file of the original along with the PDFs we create so they have a visual reference.
When I try to compile this, I keep getting a syntax error: “Expected end of line, etc. but found unknown token” with the period (.) in TiffTest.pdf highlighted.
I’ve been banging my head against this one for hours! Is there a way to avoid the JavaScript issue?
Thanks in advance.


tell application "Adobe Acrobat Professional"
	do script "this.saveAs("/Users/Shared/Work/TiffTest.pdf", "com.adobe.acrobat.tiff");"
	end tell

The posix path of the tiff file needs to be the quoted form, or the quotation marks escaped since the javascript is a text string which ends after the first parenthesis as you have it:

do script “this.saveAs(”/Users/Shared/Work/TiffTest.pdf", “com.adobe.acrobat.tiff”);"

becomes

do script “this.saveAs(” --and the rest will not compile. Should be:

do script “this.saveAs("/Users/Shared/Work/TiffTest.pdf", "com.adobe.acrobat.tiff");”

or

do script “this.saveAs(‘/Users/Shared/Work/TiffTest.pdf’, ‘com.adobe.acrobat.tiff’);”

or more completely:

do script “this.saveAs({cPath:‘/Users/Shared/Work/TiffTest.pdf’, cConvID:‘com.adobe.acrobat.tiff’});”

That way, the whole javascript string is contained by the quotes. You might run into trouble with text strings and Acrobat’s handling of Unicode text if you are using AppleScript 2 (Leopard) instead of AppleScript 1 (Tiger and older). See other thread regarding text, strings, and Unicode text here:

http://macscripter.net/viewtopic.php?id=29440

Why bother calling a piece of JavaScript for something that is available to you in plain AppleScript? From the dictionary.

save front document to file New_File_Path using conversion "com.adobe.acrobat.tiff"

pandrake & Mark67,

Thank you very much for your replies. I am using Script Editor 2 and Acrobat 8. It appears I may have run into the “trouble with text strings and Acrobat’s handling of Unicode text” issue. When I run any of pandrake’s code I get the result “undefined” and when I run Mark67’s I get “Adobe Acrobat Professional got an error: document 1 doesn’t understand the save message.”

Thank you again for your help.

Ouch. I had thought that the Unicode text string issue only effected the class of a string sent to the ‘do script’ command in Acrobat, and even with AppleScript 1 when I set the posix path of an alias it’s class is Unicode text (even when combined with regular text strings into javascript) and it errors, "Doesn’t understand ‘do script’ - exactly the opposite of what you’re getting. I do sometimes get the ‘undefined’ result from a javascript command sent thru ‘do script’ when it works, unless the javascript defines a result, but I’m assuming that whatever the result of ‘do script’ the action is not performed.

I’m not certain how this issue can effect Adobe’s ‘save’ message, tho; I thought it all had to do with the class of text of the javascript code. I’m curious, how is the variable ‘New_File_Path’ set for the save command, is it a posix path like ‘/Users/Shared/Work/TiffTest.pdf’ or an alias string like ‘Macintosh HD:Users:Shared:Work:TiffTest.pdf’ when sent to Acrobat with conversion?

Perhaps I did something wrong.
Here’s my version Mark67’s script with the Error Message, “Adobe Acrobat Professional got an error: document 1 doesn’t understand the save message.”

set posixPath1 to "/Users/Shared/Work/TiffTest.pdf"
set New_File_Path to POSIX file posixPath1 as alias
tell application "Adobe Acrobat Professional"
	save front document to file New_File_Path using conversion "com.adobe.acrobat.tiff"
end tell

And here’s my version of your script with the “undefined” error.

tell application "Adobe Acrobat Professional"
	do script "this.saveAs({cPath:'/Users/Shared/Work/TiffTest.pdf', cConvID:'com.adobe.acrobat.tiff'});"
end tell

a new file can never be an alias because an alias must exist at run time and file [alias] causes an error.
A HFS string path should work
try this


set New_File_Path to (path to shared documents as text) & "Work:TiffTest.tiff"
tell application "Adobe Acrobat Professional"
	save front document to file New_File_Path using conversion "com.adobe.acrobat.tiff"
end tell

Thanks StefanK,
That works! If I may, how can I use this to create a droplet that would use the name of whatever file I dropped onto it?

something like this, but I haven’t tested it


on open theseItems
	launch application "Adobe Acrobat Professional"
	set destinationFolder to (path to shared documents as text) & "Work:"
	repeat with oneItem in theseItems
		set theName to name of (info for oneItem)
		if theName ends with ".pdf" then
			tell application "Adobe Acrobat Professional"
				open oneItem
				set newfile to destinationFolder & text 1 thru -4 of theName & "tiff"
				save front document to file newfile using conversion "com.adobe.acrobat.tiff"
				close front document saving no
			end tell
		end if
	end repeat
	quit application "Adobe Acrobat Professional"
end open

Beautiful! :smiley:
Thank you!