Automating the creation of PDFs using InDesign

I am trying to write an applescript that will print a document using the “Save PDF as PostScript” that’s found in the print dialog box within InDesign. I would typically just write a script that would export the document as a PDF, however, for some reason our PC friends in Marketing are unable to print these PDFs. So we use Distiller on a server and print our documents to the “In” folder. The problem I am running into is when I run this script;

tell application “InDesign CS”
activate
tell application “System Events”
tell process “InDesign CS”
tell menu bar 1
tell menu “File”
click menu item “Print…”
end tell
delay 1
end tell
tell window “Print”
click button “Printer…”
end tell
end tell
end tell
end tell

The script clicks the “Printer…” button, but InDesign doesn’t respond to it. Is scripting the GUI the way to go about doing this? Or is there an easier way to script this process? Thank you in advance for any help. We are using G5 Dual 2.7 with InDesign CS.

are you still trying to figure this out ?

Why don’t script InDesign in stead of using GUI ?

Not sure if your problem is the same, but I’ve got a project backburnered which also ran into problems with GUI and Illustrator scripting:

http://bbs.applescript.net/viewtopic.php?id=18357

I am expecting to have the same issue with InDesign. Not sure if this helps or not.

Publix01, try export with options Acrobat 1.3 (version 4) this is a “flat” pdf and see if you problems are sorted? you will need to set options for the flattener. Live transparency which can be in any pdf 1.4 upwards is the most likely reason its choking. As a quick test use the PDF optimizer in acrobat to flatten one to this level.

Anther option and ai haven’t tested this yet but I’m almost positive it will work would be to save the layout as and eps then use the shell command PSTOPDF to convert it.

The problem with this method is that Adobe CS 2 files that use any of the transparency-based features. Saving as EPS will often maul Creative Suite files–change the colors, create odd raster side-effects, white backgrounds behind objects, and more. The only safe export is a PostScript (.ps) file, specifically versions 1.5 or 1.6, and creating Acrobat 6 or 7 files with that PS file using Distiller. EPS is pretty much going the way of the dinosaurs these days.

We have officially stopped using EPS to generate PDFs, nor do we save PDFs straight from Adobe Creative Suite applications, since there are too many color, quality, and compatability issues. PS-to-Distiller has been the only was to have enough consistancy and control over the PDF process.

I appreciate everyone’s help with this. We actual generate all of our PDFs using PS through Distiller. This has always given us the best results. I’m still tweaking this script but for the most part, it’s working. Thank you again to everyone who has helped me with this. It seems I’m learning something new about AppleScript everyday.

Kevin, for what its worth here’s my take on the transparency issue. There is no such thng as postscript file version 1.5 or 1.6 there are postscript levels 1, 2 & 3. There are PDF levels 1.3, 1.4, 1.5, 1.6 & now 1.7 almost every ISO standard for the graphics industry is 1.3 take a look at PDF/X or pass4press for examples. The only reasons to save above this level for print graphics would be to 1.5 to preserve layers or if you want the RIP to render the transparency by dropping the PDF directly in its print queue if this is the case then overprint must be honored. This is because every level above 1.3 can contain live transparency amongst other things. I don’t understand your comments on EPS yet insist on print to PS its pretty much one and the same thing. Only direct output to PDF can contain transparency all ouput to either EPS or PS evokes the flattener this is because postscript has no understanding of transparency only overprint can be passed on. There are no transparency handling features in Distiller because the only formats it supports don’t have any. Depending on what software the PC’s are using to print the PDF’s they should have either options to print as image or simulate overprint which should get rid of the white boxes. You should be able to save directly as PDF without any issues. If you have no control over the output device then flatten the PDF. BTW here is some syntax for illustrator that has been working fine for me its a different route to what you were trying but give it a go if using job.options is a must then this may prove to be an alternative for you.

set FilePath to (path to desktop) as string
tell application "Adobe Illustrator"
	activate
	set docRef to the current document
	tell docRef
		set DocUnits to ruler units -- To be used for math. R/O
		set ruler origin to {0, 0}
		set {LE, TE, RE, BE} to visible bounds -- This includes object strokes
		if DocUnits = millimeters then -- MM Conv Math
			set ArtW to (RE - LE) / 2.834645 as string
			set ArtH to (TE - BE) / 2.834645 as string
		end if
		if DocUnits = centimeters then -- CM Conv Math
			set ArtW to (RE - LE) / 28.34645 as string
			set ArtH to (TE - BE) / 28.34645 as string
		end if
		if DocUnits = inches then -- Inches Conv Math
			set ArtW to (RE - LE) / 72 as string
			set ArtH to (TE - BE) / 72 as string
		end if
		if DocUnits = points then -- No conversion
			set ArtW to (RE - LE) as string
			set ArtH to (TE - BE) as string
		end if
		if DocUnits = picas then -- Picas Conv Math
			set ArtW to (RE - LE) as string
			set ThePicas to round (ArtW / 12) rounding down
			set ThePoints to ArtW - (ThePicas * 12) as integer
			set ArtW to (ThePicas & "p" & ThePoints) as string
			set ArtH to (TE - BE) as string
			set ThePicas to round (ArtH / 12) rounding down
			set ThePoints to ArtH - (ThePicas * 12) as integer
			set ArtH to (ThePicas & "p" & ThePoints) as string
		end if
		if DocUnits = unknown then -- In case of pixels!!! Why NO pixels measure in script?
			set ArtW to (RE - LE) as string -- No conversion
			set ArtH to (TE - BE) as string
		end if
		tell application "System Events"
			tell process "Adobe Illustrator"
				key down option -- Can't work out how to use two modifiers?
				keystroke "p" using command down
				key up option
				delay 0.5
				keystroke tab
				keystroke ArtW -- Requires DocUnits
				keystroke tab
				keystroke ArtH -- Requires DocUnits
				keystroke return
			end tell
		end tell
		delay 2 -- Don't make this too quick
		set ruler origin to {0, 0}
		set {LE, TE, RE, BE} to visible bounds
		set Artselection to every page item
		if (LE > 0) and (BE > 0) then
			translate Artselection delta x -LE delta y -BE
		else
			translate Artselection delta x -(LE) delta y -(BE)
		end if
		set docName to name of docRef
		set docBaseName to getBaseName(docName) of me
		set newFileName to FilePath & docBaseName & ".pdf"
	end tell
	set Flat300 to {class:flattening options, clip complex regions:false, convert strokes to outlines:false, convert text to outlines:false, flattening balance:100, gradient resolution:300.0, overprint:preserve, rasterization resolution:300.0}
	save docRef in file newFileName as pdf with options ¬
		{class:PDF save options, PDF preset:"pass4press_v46", flattener settings:Flat300, font subset threshold:100}
	close docRef without saving
end tell
--
on getBaseName(fName)
	set baseName to fName
	repeat with idx from 1 to (length of fName)
		if (item idx of fName = ".") then
			set baseName to (items 1 thru (idx - 1) of fName) as string
			exit repeat
		end if
	end repeat
	return baseName
end getBaseName

Wanted to respond because while it sounds like you have alot of technical knowledge, is is vastly different than my years of “rubber hits the road” expeirence. And a quick “apology in advance” if I seem blunt…I mean no harm or disrespect by it, Mark67. It’s possible this is getting a tad Off-Topic, I’ll leave that to the moderator to decide.

I can prove this is false quite easily since we tried that for many months. The first thing doing this does is cause white backgrounds to show around any object using transparency over a spot color. Acronat 5 files are incapable of retaining accurate transparency data…we tried for months, just won’t work. Need Acrobat 6 at bare minimum, and even then the support wasn’t fool-proof across platforms until Acrobat 7.

Not actually. The practical sides are quite different. Also Adobe’s own error messages in Illustrator re-inforce the point. While the objcts may look the same in a cursory fashion, Distiller treats them quite differently. We’ve got a couple years practical experience and the machinations of 40+ artists that prove to the contrary. Even previous to transparency, EPS and PS files often yielded very different PDF files.

For years we used EPS as the medium to Distiller. That broke as soon as InDesign 2 and Illustrator CS hit the scene.

Not sure where you get this from, but my practical experience all points to this not being true. I get MORE flattener issues doing PDFs straight from Illustrator than I do using PS files as an intermediary for Distiller.

One thing neither of us have discussed which may make a difference is Spot Colors. Transparency over spot colors causes far more “breaks” in transparency rendering because it converts to CMYK when using older versions of PostScript or PDF. These CMYK conversions cause color shifts in non-spot jobs, but they are fairly subtle to the untrained eye. However, what they do to spot colors is in some cases quite horrific.

Also, my discussions with EFI technicians who work on their RIPs, as well as trying to work with ORIS, seem to have provided contrary information to yours as well. For example, ORIS can RIP transparency on-the-fly, which means the “flattener” information is not necessarily pre-done into files. Could be, but if so, Adobe has also provided enough information to do it in-RIP as well (i.e. redundant data).

Not without marginalizing color accuracy. Monitor issues notwithstanding, in the packaging world, color shifts (especially localized ones caused by the flattener) are a big deal with us. Also, on-screen presentation is just as important as printouts for doing digital approvals. So even if they’d print fine, having those white boxes in the file freaks-out on-screen-only users, despite training.

Well part of the point of PDF is “not having control over the output device.” The way we’ve worked on this (PS to Distiller) has made that easy enough to guarantee, Mac or PC. Whereas straight from Illustrator has not given us that capability. In addition it should be noted Illustrator still does not give complete control over the PDF creation process like Distiller does.

For the record, if you turn out to be an Adobe PostScript or PDF lead, I’d love to chat with you offline and have you come visit our environment. We keep being offered a personal visit from Adobe, but they keep bailing on us. We’ve made some fairly large grumblings with their developers, and I think they get nervous when large corporate customers get cranky. :wink:

I think they have lost sight of Spot Color users in a big way and are a tad out of touch with how transparency impacts those customers. Would do just about anything to rectify that situation.

I’ll give this a go when I get back to my project, thanks! :slight_smile:

I also freely admit that it’s possible you may know more “behind the scenes” information that I do, but it sounds like it varies ALOT from the “where the rubber meets the road” experience I have. I know EFI and ORIS both seemed quite surprised when we easily caused their RIPs to go into a tizzy just because we used Spot Colors and Transparency together. Took me a while to get EFI and Adobe to collectively ferret-out the issue. Bad technical decisions on both ends, as it turns out. PDF files have proven no less problematic. The Adobe CS applications were the first ones I’ve seen where it’s quite easy to make a PDF on a Mac that will display differently on a PC and even refuse to print from a PC, for example. Kinda burst my “works across platforms” bubble in a hurry.

I also admit I haven’t played with the prepress versions of PDF like PDF/X. We don’t use a strictly PDF workflow because it causes way more issues than it solves. PDFs aren’t created until separations in our workflow, and are created by the separator. But by the time THEY create PDFs, the Illustrator files aren’t even Illustrator anymore (brought into other systems), so not really relevant at that point. So aside from internal routing, handing off files to PC users, etc., we work on “native” files for as long as possible.

Hi there. We follow a similar workflow, (from .ps to Distiller) but with Quark.

Not sure if there was a reason why you weren’t using the Applescript Print functions in InDesign. I’m looking at the InDesign scripting guide (for CS2) and there is comprehensive printing info starting on page 100 (or so)

-N

Kevin, no disrespect taken and certainly none intended I was mearly attempting to help. It appears we are having totally different experiences with Adobe’s software and PDF. And just for the record I have 25 years of prepress behind me although in the last few years I’ve been working the agency side of things. I would like to see an example of the kind of files your dealing with would this be possible? Here is where I got my info from a post by Mordy Golding illustrator’s product manager

What is flattening?

Flattening is the process of removing transparency information from a file. When printing or exporting an Illustrator file to a format that does not understand Illustrator’s native transparency, overlapping transparent artwork must be broken apart into individual pieces. These individual pieces, or “atomic regions” may be vectors, rasters, or a mixture of both depending on the complexity of the original artwork.

Why is flattening necessary?

Flattening is necessary because most print devices as well as Adobe PDF prior to 1.4 (Acrobat 5 compatible) do not understand native transparency data (although some new Adobe Postscript devices do). When a file is flattened, all transparency information is removed from the file and the artwork is converted into a format that your printer or file format will understand.

When is artwork flattened?

A file is flattened when one of the following occurs:

A file that contains transparency is printed
A file that contains transparency is saved in a legacy format such as native Illustrator 8, Illustrator 8 EPS, or PDF 1.3 format (Acrobat 4 compatibility)
A file that contains transparency is exported to a vector format that does not understand transparency (PICT, EMF, WMF)
Transparent art is copied and pasted out of Illustrator into another application with both the AICB and the Preserve Appearance options checked (found in the Files & Clipboard panel in the Preferences dialog box)
The Flatten Transparency command in the Object menu is invoked

When you save an Illustrator file in certain formats, the native transparent information is kept as well as the external file format. For example, when you save a file in Illustrator 10 EPS format, the file will contain both native Illustrator data and EPS data. When you reopen the file in Illustrator, the native (unþattened) data is read. When you place the file into another application, like Adobe InDesign, the EPS (flattened) data is read.
NOTE: Adobe InDesign 2.0 can place Illustrator’s native and PDF 1.4 files with transparency intact and unflattened

Cool. I just know I can come-off as brusque and wanted to be clear I was just having a friendly discussion. :slight_smile:

If I had a dime for every time I heard that. LOL. :slight_smile:

Basically started this as early as they come on the digital side, over 15 years. Been troubleshooting PostScript printing issues since those ancient original Apple LaserWriters.

Unfortunately no. It begins with an NDA and gets a bit more complex after that. Corporate espionage concerns border on paranoia here. I think my company has better security that some much more important Federal agencies. :wink:

Just a quick note…I’ve actually picked the brains of an EFI RIP tech, and an Adobe PostScript tech, and managed to get them to talk to each other and pick-apart some of our files at the code level. So that’s my point-of-reference into the geekier side of things. If I could just get my hands on an ORIS tech for 60 minutes I could probably get my dream RIP working. :wink:

These bits are the only relevant ones, and I also don’t disagree. However, my experience is, and the feedback from the EFI/Adobe PS techs is:

Saving and file, and Exporting a file seem to invoke different routines than the Print dialog. Even creating a PS file from the Print dialog seems to use a different ruleset. My admitedly annecdotal experiences are EPS and PS can generate very different PostScript. Per above, EPS will flatten, whereas PS doesn’t seem to, or perhaps is making better use of (unþattened). This is one of those reasons why we prefer Distiller…I’m not at the mercy of the whims of support for the interpreter built-into Illustrator or inDesign.

–That Native (unþattened) data is the key to either of our points of view. My contention, Illustrator’s own export warnings, and my experience is that EPS itself as Adobe has used it (remember EPS was never meant to hold all this extra stuff) and implemented it is not the same as their PS routines.

To kinda cut to the chase though for the original poster:

Both Mark67’s point and mine are both moot if you get the results you need. I provided my info as a warning. If you don’t have problems, cool (and lucky you!). If you do, my comments give you someplace to look for trouble. :slight_smile: Sorry Publix, didn’t mean to make it any more confusing for you.

Check the link I provided earlier in the thread. Adobe’s AppleScript implementation for printing, while appearing robust on the surface, has some bugs. The key one I found was selecting page sizes. The Print Dialog over-rides the AppleScript settings no matter what you do, even according to a couple folks who tried to help me. I suspect a couple of the other page-size related attributes are also ignored as well, but can’t be sure until I can get the physical page size to behave when scripted.

My attempts currently are focusing on a hybrid approach…get the print dialog set-up via UI scripting, then use regular AppleScript to kick-off the rest of it. PreFab just updated UI Browser and their new Screen Reader feature, and that may help. I did a quick test with my nemesis, Lotus Notes, and the new PreFab UI Browser’s Screen Reader definitely exposes more tricks.

ATOMIC REGIONS!!

I love that!

The Nightmare!! has a Name… (And i’ve just been calling it “they’ve sent me another F*@king Sh@t pdf again”)

By the way i loved your FRIENDLY argument!!

We’ve been calling it “that blocking effect.” As much as I like proper terminology, I doubt I’ll be teaching designers “Atomic Regions” except for the curious. Tough enough getting them to remember that transparency is the cause for the madness 100% of the time. :wink:

Transparency has been the bane of my work existance ever since InDesign 2.x and is just as ugly now as it was then. It works pretty much as advertised for CMYK or RGB work, but goodness forbid if you use spot colors. My favorite are Adobe’s white pages and howto’s which just dismiss the issue. :stuck_out_tongue_winking_eye:

Two of my many hats, besides the obvious AppleScripting, is “Printer, PostScript, RIP, and Color Guru” and “InDesign Guru.” Just calling me MacGeek-of-all-Trades (Master-of-None-but-not-Half-Bad) probably sums it up nicely. :wink:

It can be tricky to be cordial and yet disagree. As long as everyone is on the same page on the tone, the rest is academic. I’m just glad Mark took it as intended. :slight_smile:

Calvin & publix01

I put this together following the InDesign scripting guide. It seems to work on my end for a simple “odd sized” PDF. (will dump a .ps on the desktop with the same name as the file + .ps to distill) I don’t use InDesign, so I can’t check the integrity of the resulting .ps file, nor did I go in and get crazy with the print prefs, etc.

set theFile to choose file
set theDesktop to path to desktop


tell application "Adobe InDesign CS2"
	open theFile
	set theName to name of active document
	set theHeight to page height of document preferences of active document
	set theWidth to page width of document preferences of active document
	tell print preferences of active document
		set printer to postscript file
		set paper size to custom
		set paper height to theHeight
		set paper width to theWidth
		set print file to (theDesktop & theName & ".ps" as string)
	end tell
	print active document print dialog no
	close active document saving no
end tell

HTH
-N

Kevin, we are pretty much one and the same thing my role for many years has been to test new software features before role out to production team and training users. Im responsible for all the mac admin I don’t however do PC wouldn’t know where the on button is (but then I don’t want to). If my english was half as good as my graphics this thread may not of started off sounding a little hostile but at least we have an understanding now. I apologize for the tone I was not trying to come over patronizing just matter of fact. If you want to run any tests on the file formats and live transparency then 3rd bottom preflight in Acrobat Pro 7 will do the job for you. My findings have been 100% consistent with mordys quote. What software are you using on the PC’s to view pdfs and does it have overprint preview?

Pidge, for the best way to get a visual representation of atomic regions create a new file fill background with a rectangle with fill no stroke now create a St. George’s cross with 2 more rectangles with different fills but no strokes and set some levels of transparency on these 2 items. Now select all menubar/object/flatten transparency or save down to illustrator 8 eps this is the last of the single sided eps’s when re-opening you will see all the vector art that overlaps has been sliced select all ungroup then release compound paths you can now inspect the colour fill info on the atomic vector regions.

Now throw spot colours, strokes, placed raster images and internal rester effects applied to vectors and you’ve got a big can of worms. Save that and re-open now thats flattened art the side of the eps you don’t see. The blocking as you call it is caused by your “Document Raster Effects Settings” default is 12.7mm around items. To see this create file draw rectangle fill with colour then menubar/effects/pixelate/apply mezzotint select all menubar/object/flatten transparency then menubar/veiw/show transparency grid ungroup the art and you can now inspect how the raster effect image tiles work.