At Silicon Publishing, we have been automating InDesign for over 25 years, and we’re happy to share what we’ve learned along the way. Following are some of the best practices in automating InDesign.
Before writing any code, it’s important to have a solid understanding of InDesign itself. We’ve written a post on generic InDesign Best Practices to complement this post. Beyond that foundation, template design for automation is an important component. Finally there is the work of coding, including special considerations for coding in the context of InDesign Server.
Template design is different from normal design. When designing a layout, we (designers) fit the design to the content. We might choose a particular font for the specific letters of a product name or headline. We might position elements relative to the contents of an image. Making the specific content that you have look great is a key part of graphic design.
But you can’t count on knowing what the content will be when you’re laying out a template. The words will change and the images will change.
That’s why we say that template design is different—you have to make the layout look good without knowing anything about the content.
Don’t fit the frame exactly to the placeholder text–because replacement text could be longer. Or shorter. To handle these possibilities, either:
Use the correct paragraph alignment. If the text should be center aligned, use center alignment—don’t use left alignment and drag the frame into place to position the text.
First baseline options: If your users can change fonts, consider that using the Ascent option means that the baseline of the text will vary from font to font. This can mean that text will jump higher on the page—or, worse, go overset. Instead, use the Leading option. This will guarantee that the baseline of the text will appear at the same place, regardless of the font.
Think about the “chunks” of data that exist in the layout. Does the text threading of the placeholder text frames make sense relative to the expected structure of the incoming data?
Obviously, some of the InDesign typesetting best practices have to be relaxed a bit for automation. Fine-tuning of hyphenation and line endings, for example, isn’t as relevant here.
Crop placeholder images to exactly the size of the frame. To do this, once you have the image positioned the way you want it, export it, relink or replace using the exported image, and then fit the image to the frame.
You need to do this because incoming replacement images will take on the scaling/cropping of the placeholder. In an online editing environment—at some future date—it’s confusing for users when their images are cropped and scaled when they’re added to the frame.
Cropping images to frames can also reduce the file size of your template package.
Use frame fitting options to control the way that replacement images fit to the frame.
It is not ideal to compose a very long document in scripted operation. InDesign gets slower and slower as it progresses, so it is useful to “chunk” a longer document into multiple InDesign files, then automate the concatenation of the chunks by automating InDesign’s book feature.
Document automation will almost always occur in two contexts: InDesign Server and some place that is making calls to InDesign Server. InDesign Server, as a data processor is much slower than any modern option (even just modern NodeJS). Do as much work as you possibly can outside of InDesign Server.
A few notes about data formats for automation:
Avoid “touching” the InDesign object model unless absolutely necessary. When getting the elements on a page, for example, get the elements once, rather than iterating over the collection/array. Once the data is in memory in InDesign Server, objects and arrays aren’t slow and will not be the bottleneck compared to repetitively “touching” objects in the scripting model. For example:
//Given a page object “page”:
var pageItems = page.pageItems;
//…and then iterate over pageItems
//…is faster than:
for(var x = 0; x < page.pageItems.length; x++){
//do something with page.pageItems.item(x)
}
Use allPageItems to get an array of all page items in a given container (document, page, spread, pageItem, or group), rather than recursively iterating over the page items. The allPageItems array contains all the page items in the container, regardless of their position in the object model hierarchy.
Use the direct access methods itemByName and itemByID to get a reference to a given object (a pageItem or layer, for example). These methods return a reference to an object regardless of its position in the object model hierarchy.
Use reverse iteration any time you’re changing the length of elements in a collection (pages, pageItems, layers, etc.). InDesign object collections are dynamic, and change as items are added to or deleted from the collection.
Also, be sure to follow the posts of master scripter Kris Coppieters: https://coppieters.nz/coding-without-big-words/