script for converting pdf to eps in acrobat

I’m looking for a script that would open all .pdf files within a folder, using Adobe Acrobat, and export them as .eps files

I don’t know why you would still want to use EPS nowadays, especially since Adobe stopped all development for PostScript years ago and are going the PDF way, but anyways. try this:

http://www.mombu.com/computer_design/general-photoshop/t-acrobat-save-pdf-to-eps-10767522.html

seems like they never got it to work in Acrobat 6, but it could be fixed in recent versions.

Acrobat has a relatively poor dictionary. Not many functions can be accessed thru Applescript. I have little experience scripting Acrobat myself, but so far it went without a hitch.

Good luck!

Model: MacBookPro8,2
Browser: Safari 534.51.22
Operating System: Mac OS X (10.7)

Hello.

If you wanted to drop the Adobe Acrobat requirement, and installed Ghost Script from Mac Update
then you could have had a commandline like this within an Applescript or whatever.

gs -sDEVICE=epswrite -sOutputFile=foo.eps foo.pdf

But maybe this won’t work for you, it is a little dependent of the standard of the pdf I guess.

But it is still worth a try.

Thanks guys, I appreciate your input. So here is what I’m trying to use:

set sourceFile to choose file with prompt “Choose File?”
set targetFile to choose folder with prompt “Destination Folder?”

try
set AppleScript’s text item delimiters to “:”
set docName to last text item of sourceFile
set AppleScript’s text item delimiters to “”
tell application “Adobe Acrobat Pro”
–get postScript level of EPS Conversion
– returns: “Can’t get postScript level of EPS Conversion.”
–set postScript level of EPS Conversion to 2
– returns: “Can’t set «class ppsl» of «class xEPS» to 2.”
–set PDF2EPS to make new EPS Conversion with properties {postScript level:2}
– returns: “Acrobat got an error: Can’t make a EPS Conversion.”
–make new conversion with properties {name:“PDF2EPS”}
– returns: “Acrobat got an error: Can’t make a conversion.”
–set properties of EPS Conversion to {postScript level:2, binary:false, embedded fonts:true, annotation:false, halftones:true, images:false, preview:false, TrueType:true}
– returns: “Can’t set every property of «class xEPS» to {«class ppsl»:2, «class pbin»:false, «class pfnt»:true, «class anot»:false, «class phlf»:true, «class pimg»:false, «class pprv»:false, «class ptyp»:true}.”
–get name of every EPS Conversion
– returns: {true}

	-- Settings I want to use
	-- {postScript level:2, binary:false, embedded fonts:true, annotation:false, halftones:true, images:false, preview:false, TrueType:true}
	open alias sourceFile with invisible
	save document docName to targetFile using EPS Conversion with embedded fonts, halftones and TrueType without binary, annotation, images and preview
	-- works, but defaults to PostScript level as set in the UI.
	--save document docName to targetFile using EPS Conversion with properties {postScript level:2, binary:false, embedded fonts:true, annotation:false, halftones:true, images:false, preview:false, TrueType:true}
	-- compilation error: Expected end of line, etc. but found "{".
	--save document docName to targetFile using EPS Conversion with postScript level 2, embedded fonts, halftones and TrueType without binary, annotation, images and preview
	-- compilation error: Expected end of line, etc. but found number.
	close document docName saving no
end tell

on error errMsg number errNum
errMsg
end try

and this is my result: “Can’t get last text item of alias "Macintosh HD:Users:greg:TestFile.pdf".”

I apologize if I’m missing the obvious, I’m very new to applescript.

trying this:
set sourceFile to “Macintosh HD:Users:greg:TestFile.pdf”
set targetFile to “Macintosh HD:Users:greg:TestFile.eps”

try
set AppleScript’s text item delimiters to “:”
set docName to last text item of sourceFile
set AppleScript’s text item delimiters to “”
tell application “Adobe Acrobat Pro”
–get postScript level of EPS Conversion
– returns: “Can’t get postScript level of EPS Conversion.”
–set postScript level of EPS Conversion to 2
– returns: “Can’t set «class ppsl» of «class xEPS» to 2.”
–set PDF2EPS to make new EPS Conversion with properties {postScript level:2}
– returns: “Acrobat got an error: Can’t make a EPS Conversion.”
–make new conversion with properties {name:“PDF2EPS”}
– returns: “Acrobat got an error: Can’t make a conversion.”
–set properties of EPS Conversion to {postScript level:2, binary:false, embedded fonts:true, annotation:false, halftones:true, images:false, preview:false, TrueType:true}
– returns: “Can’t set every property of «class xEPS» to {«class ppsl»:2, «class pbin»:false, «class pfnt»:true, «class anot»:false, «class phlf»:true, «class pimg»:false, «class pprv»:false, «class ptyp»:true}.”
–get name of every EPS Conversion
– returns: {true}

	-- Settings I want to use
	-- {postScript level:2, binary:false, embedded fonts:true, annotation:false, halftones:true, images:false, preview:false, TrueType:true}
	open alias sourceFile with invisible
	save document docName to targetFile using EPS Conversion with embedded fonts, halftones and TrueType without binary, annotation, images and preview
	-- works, but defaults to PostScript level as set in the UI.
	--save document docName to targetFile using EPS Conversion with properties {postScript level:2, binary:false, embedded fonts:true, annotation:false, halftones:true, images:false, preview:false, TrueType:true}
	-- compilation error: Expected end of line, etc. but found "{".
	--save document docName to targetFile using EPS Conversion with postScript level 2, embedded fonts, halftones and TrueType without binary, annotation, images and preview
	-- compilation error: Expected end of line, etc. but found number.
	close document docName saving no
end tell

on error errMsg number errNum
errMsg
end try

I get this result: “Adobe Acrobat Pro got an error: document "TestFile.pdf" doesn’t understand the save message.”

I got it this far, just can’t get over the same error message you had. I’ve made some improvements, mostly fitlering out only PDF files at the first line and changing the extension from .pdf to .eps while creating the save file path…

Sorry I couldn’t get it to work. Maybe someone with more experience with Acrobat scripting could help…

set sourceFile to choose file with prompt "Choose File?" of type {"pdf"}
set targetFolder to choose folder with prompt "Destination Folder?"

try
	set oldTID to AppleScript's text item delimiters
	set AppleScript's text item delimiters to ":"
	set docName to last text item of (sourceFile as string)
	set AppleScript's text item delimiters to oldTID
	
	set oldASTID to AppleScript's text item delimiters
	set AppleScript's text item delimiters to ".pdf" -- the string to search for
	set tempString to text items of docName
	set AppleScript's text item delimiters to ".eps"
	set docNameToSaveTo to tempString as string
	set AppleScript's text item delimiters to oldASTID
	
	--set docNameToSaveTo to ("EPS_" & docName) as string
	set docToSavePath to (((targetFolder as string) & docNameToSaveTo) as string) --as alias
	
	tell application "Adobe Acrobat Pro"
		open sourceFile --as alias --with invisible
		set actDoc to active doc
		tell application "Adobe Acrobat Pro" to save actDoc to docToSavePath using EPS Conversion --with embedded fonts, halftones and TrueType without binary, annotation, images and preview
		close actDoc saving no
	end tell
on error errMsg number errNum
	(errNum & " : " & errMsg) as string
end try

Had a flash. I had an old script that used to combine PDF files and noticed I was missing one keyword in the save command: file. It was that stupid. the AS dictionary for Acrobat is not very well written. :confused:

Try this:

set sourceFile to choose file with prompt "Choose File?" of type {"pdf"}
set targetFolder to choose folder with prompt "Destination Folder?"

try
	set oldTID to AppleScript's text item delimiters
	set AppleScript's text item delimiters to ":"
	set docName to last text item of (sourceFile as string)
	set AppleScript's text item delimiters to oldTID
	
	set oldASTID to AppleScript's text item delimiters
	set AppleScript's text item delimiters to ".pdf" -- the string to search for
	set tempString to text items of docName
	set AppleScript's text item delimiters to ".eps" -- the string to replace the found string with
	set docNameToSaveTo to tempString as string
	set AppleScript's text item delimiters to oldASTID
	
	set docToSavePath to (((targetFolder as string) & docNameToSaveTo) as string)
	
	tell application "Adobe Acrobat Pro"
		open sourceFile --with invisible
		set actDoc to active doc
		tell application "Adobe Acrobat Pro" to save actDoc to file docToSavePath using EPS Conversion with embedded fonts, halftones and TrueType without binary, annotation, images and preview
		close actDoc saving no
	end tell
on error errMsg number errNum
	(errNum & " : " & errMsg) as string
end try

Thank you so much, leonsimard! It works like a charm

You’re welcome. I noticed I left a few things unfinished within the code. I had commented out a few things that were unnecessary.

Also, not sure if opening the file with the invisible attribute is gonna work well. Try it out with and without and see.

Good luck!

Will do! Thanks again.

I’ve stumbled across another issue. I’m trying to modify the following script:

set sourceFile to choose file with prompt “Choose File?” of type {“pdf”}
set targetFolder to choose folder with prompt “Destination Folder?”

to open ALL pdf files within a folder and save to an output folder. Would love your help in finding a solution for that.

I’m trying to use:

tell app “Finder” to set theFiles to every document file of folder “Macintosh HD:Full:Path:To:Your:Folder” whose file type begins with “pdf”

and receiving this error:

error “Can’t get every document of "Macintosh HD:Users:greg:Desktop:pdf_Resource".” number -1728 from every document of “Macintosh HD:Users:greg:Desktop:pdf_Resource”

Hello.

You have used the wrong attribute: try with name extension instead of file type.

This worked for me:

tell application "Finder" to set theFiles to every file of folder targetFolder whose name extension begins with "pdf"

hmm, I’m getting an error while using:

tell application “Finder”
set sourceFiles to every file of folder “Macintosh HD:Users:greg:Desktop:pdf_Resource” whose name extension begins with “pdf”
set targetFolder to choose folder with prompt “Destination Folder?”
end tell
try
set oldTID to AppleScript’s text item delimiters
set AppleScript’s text item delimiters to “:”
set docName to last text item of (sourceFiles as string)
set AppleScript’s text item delimiters to oldTID

set oldASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to ".pdf" -- the string to search for
set tempString to text items of docName
set AppleScript's text item delimiters to ".eps"
set docNameToSaveTo to tempString as string
set AppleScript's text item delimiters to oldASTID

--set docNameToSaveTo to ("EPS_" & docName) as string
set docToSavePath to (((targetFolder as string) & docNameToSaveTo) as string) --as alias

tell application "Adobe Acrobat Pro"
	open sourceFiles --as alias --with invisible
	set actDoc to active doc
	tell application "Adobe Acrobat Pro" to save actDoc to file docToSavePath using EPS Conversion --with embedded fonts, halftones and TrueType without binary, annotation, images and preview
	close actDoc saving no
end tell

on error errMsg number errNum
(errNum & " : " & errMsg) as string
end try

error:
“-1700 : Can’t make «class docf» "file1.pdf" of «class cfol» "pdf_Resource" of «class cfol» "Desktop" of «class cfol» "greg" of «class cfol» "Users" of «class sdsk» of application "Finder" into the expected type.”

Hello try this quick fix which I for obvious reasons can’t test. :slight_smile:

Reading your error message, it seems to me that the problem is that your file list, contains Finder Files, I think you should try:

 set sourceFiles to every file of folder "Macintosh HD:Users:greg:Desktop:pdf_Resource" whose name extension begins with "pdf" as alias as list

And take it from there. You should also try having more on error blocks to pin point where the error occurs better.

HTH :slight_smile:

that is returning this error:
error “File pdf wasn’t found.” number -43 from “pdf”

Hello.

Try this: You’ll just use theAliases instead of theFiles down your script.

set theAliases to {}
tell application "Finder"
	set theFiles to every file of folder alias "Macintosh HD:Users:greg:Desktop:pdf_Resource" whose name extension begins with "pdf"
	repeat with aFile in theFiles
		set end of theAliases to contents of aFile as alias
	end repeat
end tell

hmmm, still no luck. I’m still getting the error.

Hello.

I advice you to insert more on error try blocks, so that you can pinpoint exactly where the error occurs.

Well, the solution is a bit more complex. You need two separate “modules”.

The first one would manage files inside a folder the user selected and also the output folder. There needs to be a repeat loop within this module to cycle thru the files, checking if they end with .pdf, then send each one to the second module.

The second module is basically what you had so far, the one that was working. It just takes the file that’s coming in, processes it and then ends.

The first module takes time to create. But you should be able to easily find something already made within these forums, this is a fairly common thing. Here’s a few suggestions:

http://macscripter.net/viewtopic.php?id=16694
http://macscripter.net/viewtopic.php?id=22609
http://macscripter.net/viewtopic.php?id=8049 third post specifically, without the ticks thing

Good luck!

Browser: Safari 536.26.17
Operating System: Mac OS X (10.8)

Thanks for pointing me in the right direction, leonsimard. I’ll take a look at those threads, and see if I can get it working.