Photoshop CS3 PDF to JPG save issue


I will admit to be a novice at scripting and I’ve got a problem possibly just relating to CS3 but it could be something very simple I’m missing.

My office has just installed an Odystar PDF workflow solution. One of the things we are trying to do is automate a lot the time-consuming jobs like convert PDF to JPG. The code works and creates a PDF as required but the filename goes wrong. It always tags a -1 copy after the filename before the extension.

I don’t know what the difference between save…with copying and save…without copying is other than without copying leaves photoshop waiting for the user to click on the save button, not great when the actions run on a remote server which the user can’t see.

Does anyone know what’s causing the -1 copy or how to prevent it?

Thanks in advance

on SetupOdyStarScript()
	return "Success"
end SetupOdyStarScript
on FinalizeOdyStarScript()
	return "Success"
end FinalizeOdyStarScript
on DoOdyStarAction(inInputFile, inOutputFile, inParameter)
	-- inInputFile contains the full path to the file
	tell application "Adobe Photoshop CS3"
		open inInputFile as PDF with options ¬
				{class:PDF open options, mode:RGB, resolution:72}
		-- opens file at 72 dpi
		set docName to name of document 1
		-- sets docname to the filename of the open document
		set myFile to (((("OdystarX:PS AUTO DROP:PS Action IN:PDF TO LR JPEG:") as string) & docName & ".jpg") as file specification)
		-- defines a different filepath for the document and keeps the same filename but with jpg extension
		set myOptions to ¬
			{class:JPEG save options, embed color profile:true, format options:standard, quality:8}
		-- defines save options
		save current document in myFile as JPEG with options ¬
			myOptions with copying
		-- saves the file
		close document 1 without saving
	end tell
	return "Success"
end DoOdyStarAction

You may need to do some manipulation of the filename to get it to save it with the right file extension, etc.

set myPath to something -- path of original file

repeat with i from 1 to ((count of every character of myPath) - 4) -- chop off file extension ".pdf"
	set newName to newName & (item i of myPath)
end repeat

set newName to newName & ".jpg"

I think you need to turn off the ‘with copying’ in the save command - that may be where your file naming problem is coming from. If you need to flatten the image, resize, etc, you can write a photoshop action to do all that & call it with “do action”.

Also, you don’t have to do “open as PDF” - plain old “open” should work.

See if any of this is useable:

tell application "Adobe Photoshop CS3"
		open myFile with options {bits per channel:eight, crop page:bounding box, mode:RGB, resolution:150, use antialias:true}
		tell current document
			do action "prepare for jpeg" from "my actions" -- call a photoshop action here
			save it in newname as JPEG with options {embed color profile:false, matte:none, quality:5}
			close it
		end tell
	end tell

Thanks for the reply, the problem is if I change the with copy to without copy Photoshop will sit and wait until the save button is clicked. I’m wondering if this is default behaviour and if there is a click save option that can be scripted.

If not I’ll need to add a bit to the script to rename the file after it’s saved but it seems messy.

If you are saving into a new file location then you do not need to use the “with copying” parameter. If you were to perform multiple saves from one open file then the variable reference to the original opened document is kept alive when using the “with copying” parameter with each save. This waits for nothing for me anyhow but I don’t have CS3 to test.

set x to choose file
set y to (choose folder) as text

my DoOdyStarAction(x, y)

on DoOdyStarAction(Input_File, Output_Folder)
	tell application "Adobe Photoshop CS2"
		open Input_File as PDF with options {class:PDF open options, mode:RGB, resolution:72}
		set Doc_Ref to the current document
		tell Doc_Ref
			set Doc_Name to name
			set New_File to Output_Folder & Doc_Name & ".jpg"
			save in New_File as JPEG with options ¬
				{class:JPEG save options, embed color profile:true, format options:standard, quality:8}
		end tell
		close current document without saving
	end tell
	return "Success"
end DoOdyStarAction