Scripting InDesign to Create PDF files

Hello,
I have a script that takes quark files, opens them and makes PDF’s. I have been trying to get the same results by dragging inDesign CS2 documents on the script…But nothing has worked…here is the original quark script…I already tried to change all the quark stuff to indesign and changed any of the menu terminology, but no go…so, I am posting the original…any guidance to making InDesign file(s) do the same thing would be most appreciated…
thanks~!
barbara

on open (ItemList)
repeat with thisItem in ItemList
processfile(thisItem, “dropherehere”)
end repeat
end open

on processfile(myfile, mymethod)
tell application “QuarkXPress”
activate

    if mymethod = "drophere" then
        open file (myfile as string)
    end if
    
end tell
try
    tell application "System Events"
        tell process "QuarkXPress"
            tell menu bar 1
                tell menu bar item "File"
                    tell menu "File"
                        tell menu item "Export"
                            keystroke return
                            tell menu "Export"
                                keystroke return
                                
                            end tell
                        end tell
                    end tell
                end tell
            end tell
            delay 5
            keystroke return
            keystroke return
            keystroke return
            
            tell window "Export as PDF"
                keystroke return
                
                click button "Save"
            end tell
        end tell
    end tell
    delay 5
end try
if mymethod = "drophere" then
    tell application "QuarkXPress"
        activate
        close document 1 saving no
    end tell
end if

end processfile

Good morning barbara, what pdf export preset or options are you trying to use for your export?

Additionally InDesign supports exporting to PDF without having to utilize GUI Scripting. Here’s a pure AppleScript method that may work for you.

on open fileList
	tell application "Finder"
		repeat with i from 1 to count of items of fileList
			set theFile to item i of fileList
			set {filePath, fileName} to {container, name} of theFile
			if fileName ends with ".indd" then my createPDF(theFile, filePath as Unicode text, (text 1 thru -6 of fileName))
		end repeat
	end tell
end open

on createPDF(theFile, savePath, docName)
	tell application "Adobe InDesign CS3"
		open theFile
		set theProps to properties of PDF export preset "[Smallest File Size]"
		set newProps to {view PDF:true, page range:"2", crop marks:true, bleed marks:true, color bars:true, registration marks:true} & theProps
		set oldProps to properties of PDF export preferences
		set properties of PDF export preferences to newProps
		export front document format PDF type to (savePath & docName & ".pdf") without showing options
		set properties of PDF export preferences to oldProps
		close front document saving no
	end tell
end createPDF

Good morning James,

I have a setting called lowres mag that I use…but probably the print or standard would work as well…
I did save your script as an application, but when I drag my file on it, it doesn’t seem to launch.
Is there something in the script I need to change to point to something on my machine?

thanks so much for your help… :slight_smile:
barb

This might not be a help…

But if you have a copy of Acrobat, you can drag the indesign file directly onto acrobat and it will make a pdf.

You can also use the combine multiple files into one pdf command in acrobat…

No scripting needed!

Also works with illustrator files

:slight_smile:

One more thing, I just purchased the Quark action pack for automator from automatedworkflows.com.

The action pack was useless to me, except for the “export to eps” action…

I used it to make an automator droplet where I could drop QXD docs on it, it would make an EPS file, then copy the files to a folder I specified. Then, I had Acrobat distiller watch that folder, and it will convert the EPS into a PDF, then delete the original EPS files… the action pack was $15 and SO totally worth it for the project I was on.

They also have an Automator pack for indesign, and includes the action for making a PDF…you can download a demo from them, and depending on what you’re using this for, you might want to go ahead and just pay the $15…

good luck!

hello there monkey…humper

I tried to go directly from to Acrobat, dragging an INDD on the acrobat icon or doing a create pdf from file option in the application, but I get the following messages:

“Invalid value for using the parameter using of event ExportFile. Expected PDFexport preset, but received “standard””
Then I click Ok and get another message…basically cannot do it cause its not a supported file type…

How did you bring it into ACROBAT??

also, I bought that entire workflow package…I think I got the entire one that included InDesign… I’ll have to check it out…

Keep me posted on the direct to acrobat… Would love to get that to work :wink:

barbara

Hi Barbara,

The script that James posted works like a charm when I try it … you have to save it as an application, then drag .indd files to it. Only potential issue is that it balks if the .indd files contain missing or modified links.

But it sure beats the heck out of gui-scripting quark! welcome to the 21st century!

My apologies to James!!!
The script does work !!!
I tested it originally on my laptop which is running 10.5. My iMac, is running 10.4 and it worked fine :wink:
I figured if Mister Friendly got it to work no problem, let me try it on this machine…
That must have been the problem??
I’m going to play with it and see if I need any tweaks…but so far so good.
Thanks for not letting me give up on it!!!
babs

Hello again…
nevermind… it works on 10.5…it must have been a missing font image problem.
I love it!!!
thank you al so much!!
barbara

Glad to see it’s working Barbara!

thanks James…and sorry for the mishap…I don’t know…somedays I think maybe it just needs a new day and then its just fine :wink:
I truly appreciate the help…I did take out the crop marks for this particular one and the color bars etc…but, the code is very helpful in studying it for future needs :wink:
again…thanks!!!

Woah woah woah, did I say you can remove crop marks? I didn’t think so!

Just kidding =) Glad that I was able to be helpful.

Just wanted to say that if you have Distiller you can generate a PS file from Quark and Distill it to a pdf.
No GUI scripting required :wink:

I’ve also managed to account for just about every dialog Quark can throw up which can be a pain.

Regards,

Nick

You could make your droplet such that you could drag a Quark doc on it or an InDesign doc and it would handle them. Something like:

tell application "System Events"
		set the item_info to info for this_item
		if not ((kind of item_info starts with "Quark") or (kind of item_info starts with "InDesign")) then
			tell application "Finder" to activate
			display dialog "This file is not an InDesign or Quark document!" buttons "Skipping" default button "Skipping" with icon 0 giving up after 6
			return
		end if
	end tell
	--Determine whether to use InDesign subroutines or Quark subroutines
	if (kind of item_info starts with "InDesign") then
		tell application "Adobe InDesign CS3"
			--Do the InDesign print routine
		end tell --End tell InDesign

	else --Process Quark files
		tell application "QuarkXPress"
			--Do the Quark print stuff
		end tell --End tell Quark

Hey Matt-Boy,
Funny, I was wondering if I could figure out a way to do both at the same time…
Would love to try this…
How do I get it to allow me to drop files on it??
I saved it as an app…but nothing happens when I drag a file on top of it?
thanks
barbara

Here’s a slightly modified version of Matts that will accept either file type. I broke the actual create routines off into their own handlers because I like to keep things modular. You will have to fill in the script portion for the Quark because I dont actually have it to test with.

on open fileList
	tell application "Finder"
		repeat with i from 1 to count of items of fileList
			set theFile to item i of fileList
			if not ((kind of theFile starts with "Quark") or (kind of theFile starts with "InDesign")) then
				display dialog "This file is not an InDesign or Quark document!" buttons "Skipping" default button "Skipping" with icon 0 giving up after 6
				return
			end if
			--Determine whether to use InDesign subroutines or Quark subroutines
			if (kind of theFile starts with "InDesign") then -- Process as InDesign
				set {filePath, fileName} to {container, name} of theFile
				my createInDesignPDF(theFile, filePath as Unicode text, (text 1 thru -6 of fileName))
			else -- Process as Quark
				my createQuarkPDF()
			end if
		end repeat
	end tell
end open


on createInDesignPDF(theFile, savePath, docName)
	tell application "Adobe InDesign CS3"
		open theFile
		set theProps to properties of PDF export preset "[Smallest File Size]"
		set newProps to {view PDF:true, page range:"2", crop marks:true, bleed marks:true, color bars:true, registration marks:true} & theProps
		set oldProps to properties of PDF export preferences
		set properties of PDF export preferences to newProps
		export front document format PDF type to (savePath & docName & ".pdf") without showing options
		set properties of PDF export preferences to oldProps
		close front document saving no
	end tell
end createInDesignPDF

on createQuarkPDF()
	-- Your Quark Routine
end createQuarkPDF

Hi James,
I didn’t want to write so fast this time, just in case it was my weird laptop problem again…
The InDesign one works perfect…but the quark one doesn’t… It doesn’t even opens the file when I drop it onto the script icon.
I am using quark 7.0. Is there anything else I should have set in quark preferences or the printer/system preferences for that part to work…
That would be awesome if I could do a 2 for 1 :wink:
thanks!!!
babs

Hi barbara, did you fill in your quark code into the script? I don’t have Quark to actually test this, but given the code you provided earlier I would try something like this.

on open fileList
	tell application "Finder"
		repeat with i from 1 to count of items of fileList
			set theFile to item i of fileList
			if not ((kind of theFile starts with "Quark") or (kind of theFile starts with "InDesign")) then
				display dialog "This file is not an InDesign or Quark document!" buttons "Skipping" default button "Skipping" with icon 0 giving up after 6
				return
			end if
			--Determine whether to use InDesign subroutines or Quark subroutines
			if (kind of theFile starts with "InDesign") then -- Process as InDesign
				set {filePath, fileName} to {container, name} of theFile
				my createInDesignPDF(theFile, filePath as Unicode text, (text 1 thru -6 of fileName))
			else -- Process as Quark
				my createQuarkPDF(theFile)
			end if
		end repeat
	end tell
end open


on createInDesignPDF(theFile, savePath, docName)
	tell application "Adobe InDesign CS3"
		open theFile
		set theProps to properties of PDF export preset "[Smallest File Size]"
		set newProps to {view PDF:true, page range:"2", crop marks:true, bleed marks:true, color bars:true, registration marks:true} & theProps
		set oldProps to properties of PDF export preferences
		set properties of PDF export preferences to newProps
		export front document format PDF type to (savePath & docName & ".pdf") without showing options
		set properties of PDF export preferences to oldProps
		close front document saving no
	end tell
end createInDesignPDF

on createQuarkPDF(theFile)
	tell application "QuarkXPress" to open theFile
	try
		tell application "System Events"
			tell process "QuarkXPress"
				tell menu bar 1
					tell menu bar item "File"
						tell menu "File"
							tell menu item "Export"
								keystroke return
								tell menu "Export"
									keystroke return
								end tell
							end tell
						end tell
					end tell
				end tell
				delay 5
				keystroke return
				keystroke return
				keystroke return
				tell window "Export as PDF"
					keystroke return
					click button "Save"
				end tell
			end tell
		end tell
		delay 5
	end try
	try
		tell application "QuarkXPress"
			activate
			close document 1 saving no
		end tell
	end try
end createQuarkPDF

Well James…we are getting much closer…the quark file opens up and I here it doing a few things, and it closes the file, but no pdf is made… I will have to study the other quark script with yours and see if I can find the difference… The Indesign part is working like a charm…I’m gonna keep playing with it…
I thank you immensely as always for all your help and guidance… I can’t tell you how valuable it is…I find this stuff very difficult to learn in a book and the dictionaries make me nuts…reading good scripting like yours, really helps me a lot :wink:
thanks
babs

Sorry, Barbara…

My team encountered your exact problem (no ‘standard’ preset) when dragging INDD files to acrobat.

The problem lies with Acrobat telling itself that there is a ‘standard’ preset to begin with. (there isn’t, at least in the English version)

Go to Acrobat Prefs / Categories: Convert to PDF / Converting to PDF: Indesign / Edit Settings button /

You have to change the setting from Standard to whichever you prefer…

Works like a charm

:o)