Log
Notes on XML and Scripting InDesign
I’ve been working on a catalog in InDesign CS2 using data pulled from a database. Documentation on automation is rather, shall we say, scarce, so here’s a few pointers that I’ve learned.
If you’re planning on generating XML to automate layout in InDesign, first design a discrete unit and then drag it over into the Structure pane and export the XML. This will save you many excruciating moments trying to figure out what InDesign actually wants.
When using tables in XML, you must use the
TableandCellelements. To have them show up as tables, you also need to namespace them and add the correct attributes, including the number of rows and columns. For example:<Table xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" aid:table="table" aid:trows="2" aid:tcols="3"> <Cell aid:table="cell" aid:theader="" aid:crows="1" aid:ccols="1">Header Text</Cell> <Cell aid:table="cell" aid:theader="" aid:crows="1" aid:ccols="1">Header Text</Cell> <Cell aid:table="cell" aid:theader="" aid:crows="1" aid:ccols="1">Header Text</Cell> <Cell aid:table="cell" aid:crows="1" aid:ccols="1">Cell Text</Cell> <Cell aid:table="cell" aid:crows="1" aid:ccols="1">Cell Text</Cell> <Cell aid:table="cell" aid:crows="1" aid:ccols="1">Cell Text</Cell> <Cell aid:table="cell" aid:crows="1" aid:ccols="1">Cell Text</Cell> <Cell aid:table="cell" aid:crows="1" aid:ccols="1">Cell Text</Cell> <Cell aid:table="cell" aid:crows="1" aid:ccols="1">Cell Text</Cell> </Table>You can’t directly access a TextFrame’s tables when they’re placed by XML. Instead, you need to use the associated xml element as such:
[xmlElement].parentStory.tables.item (0)The item “attribute” appears to act like a method rather than an array—you have to use parentheses when using it rather than brackets.
item (0)NOTitem[0].When applying an object style to a TextFrame, you also need to apply the paragraph style associated with the object style to the xml element’s parentStory as such:
[xmlElement].parentStory.appliedParagraphStyle = [objectParagraphStyle];Scripts seem to run much faster with InDesign hidden, at least when you’re running them from Adobe’s ExtendScript Toolkit
To use images in XML, you must use
<Image>as the tag. Then use thehrefattribute to specify where your linked image file is coming from. You must use thefileprotocol, as such:<Image href="file://images/image.tif">. You can use either relative or absolute URLs to specify the location. It seems best to use relative, especially if you’re handing off the file to someone else. You can use either the single tag form:<Image />or the two tag form:<Image></Image>, but if you have any text between the open and closing tags, the linked image will be replace with the text.Update 4/17/07: The solution to my most annoying problem: getting all the textFrame settings to match what you’ve specified in the Object Style, particularly vertical alignment:
for (var i in [textFrame].textFramePreferences) { if ([textFrame].appliedObjectStyle.textFramePreferences[i] && i != 'parent') { [textFrame].textFramePreferences[i] = [textFrame].appliedObjectStyle.textFramePreferences[i]; } }- Update 4/30/07: When a textFrame is placed outside of the page boundaries, it isn’t possible to access it via a page reference as such
[document].[page].textframes. Instead, use a spread, as such[document].spreads.lastItem().textframes. - Update 8/14/07: If the first image in the XML can’t be found, you’ll be prompted to select every image. It’s pretty annoying. If there are missing images later on in your XML, you’ll be prompted to selected them, but it will only occur for missing images.
12/15/06 08:03AM Design Geekiness
Comments
Cristiana—you need to place the table tags inside an xml element that maps to a textframe’s tag. For example, if you have an element “tablewrapper” that wraps your table, you need to tag the textframe “tablewrapper”.
03/08/07 10:34PM
Hi :-)
I have tried to put the table-xml above into my xml document but InDesign will not import it (my script and xml works fine without the table-xml).
Is it possible you could make an full example and put it on this site? An xml document with the table and a script to place the data.
Thanks in advance,
Lars
12/10/07 3:22AM
Very interesting information.
Thank You.
But one thing…
You need not to use the <Image>-Tag for images. Any tag with a href-attribute will do.
Example:
<MyBeautifulPicture href=”file://img.png” />
06/11/08 3:59AM
Does anybody have an idea how to make an objectstyle linked to an object(image)?
I know that the cellstyle can be defined with aid5:cellstyle=” “
and tablestyle with aid5:tablestyle=” ”
but how do you define an objectstyle? aid5:objectstyle=” ” does not work.. any other ideas?
thank you very much
02/20/09 2:26AM
Add a Comment
Have something to say about what I wrote here? Let’s hear it!
- Your name and email address are required, but your email will not be displayed on the site
- If you provide a URL, a link to your site will appear
- You may use the following HTML:
<strong>bold</strong><em>italic</em><a href="http://url">links</a>
- Double line breaks will be converted to paragraphs.
- As you type, you should get a nice little preview of your comment directly below the text box.
- I reserve the right to edit any comment for any reason (I’ll be reasonable).
Recently Played on iTunes
-
“My Sharona”
Frat Rock: The '70s
The Knack
06/04/11 09:27 -
“The KKK Took My Baby Away”
Anthology
The Ramones
06/04/11 09:25 -
“My Sharona”
Frat Rock: The '70s
The Knack
06/04/11 09:24
Cristiana:
Hi, this few pointers are very useful. I ask you: “how can I markup TextFrame’s tables with my XML?”
Thanks in advance,
Cristiana
02/26/07 1:21PM