script for converting pdf to eps in acrobat

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.

Thanks again, works like a charm.
I ended up with this script:

set thefolder to choose folder with prompt "Source Folder?"
set targetFolder to choose folder with prompt "Destination Folder?"


tell application "Finder"
	set newFileList to {}
	set filelist to every item of entire contents of thefolder
	repeat with myFile in filelist
		if name of myFile ends with ".pdf" then
			set end of newFileList to myFile
		end if
		
		
		try
			set oldTID to AppleScript's text item delimiters
			set AppleScript's text item delimiters to ":"
			set docName to last text item of (myFile 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 myFile --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
		
	end repeat
end tell

Good. Glad to know it works. :wink:

a bit easier


set thefolder to choose folder with prompt "Source Folder?"
set targetFolder to (choose folder with prompt "Destination Folder?") as text


tell application "Finder" to set filelist to every item of entire contents of thefolder
repeat with myFile in filelist
	set {name:fileName, name extension:fileExtension} to myFile
	if name extension of myFile is "pdf" then
		try
			set docNameToSaveTo to text 1 thru -5 of fileName & ".eps"
			set docToSavePath to targetFolder & docNameToSaveTo
			tell application "Adobe Acrobat Pro"
				open file (myFile as text)
				save document 1 to file docToSavePath using EPS Conversion --with embedded fonts, halftones and TrueType without binary, annotation, images and preview
				close document 1 saving no
			end tell
		on error errMsg number errNum
			display dialog "An error occurred: " & errNum & " - " & errMsg buttons {"Cancel", "OK"} default button "OK"
		end try
	end if
end repeat


Thanks Stefan, I’ll give that a try. I appreciate your help.

I’m trying to do the same thing with saving to Postscript (ps). I don’t see in the code anywhere to set the postscript level to 2, although the op had that in their code.

You must be using an old RIP to need Level 2… If you look at Acrobat’s Applescript dictionary, under EPS conversion, there is a option to set the postscript level :

postScript level (integer) : The PostScript Language Level. Levels 2 and 3 are supported, but not Level 1.

I don’t think you’re gonna have plain PS. EPS should work as well as PS, Distiller should accept them, if that’s what you’re using.

But why use PS? Or EPS for that matter? PDF is much, much better and modern, plus supports native transparency. I don’t see the need for a format that’s no longer supported, unless you’re using very old RIPs or apps.

level 2 seems to be the default level


tell application "Adobe Acrobat Pro"
	set psLevel to postScript level of conversion "com.adobe.acrobat.ps" --> 2
end tell

Thanks.

The only issue I had with your script was that it went too fast, so that the names of one file were being applied to the name of a different output file. I’ll try to figure that out another time.

P.S. The reason to output as ps, is that was the only way to get the pdf file to a reasonable size. For some reason, optimized just added to the file size, even after checking all the options and leaving images to downsize to 150 whle embedding subsets. Reduce file size pdf only reduced it by less than 1 MB. Put when I saved the pdf as a postscript and redistilled it at the smallest file size preset, I got a reduction of about 40%.

I see. I’ve seen that before. Main reason is, there is a lot more junk in PDF than there was in a PS. I use the optimize command inside Acrobat, but Acrobat being severely limited in its Applescript dictionary, there seem to be no way to automate this, I’ve looked. I abandonned quickly though, sizes of PDF files never been an issue yet.

Changing the resolution of images when creating the PDF does not remove a lot of junk that seem to be useless, as when it is removed with Acrobat, it still works just fine.

Converting from CMYK to RGB helps always, cropping images to frames also. Have you tried lowering the version of the PDF file when it’s created? 1.4 should be a minimum.

As for the script going too fast, that is surprising. I’ve never had that problem before in similar scripts.