Introduction
The Post Population pane in Field Options provides options for image frames and text fields.
For image frames, you can assign alternative text (“Alt Text”) for PDF export, helping create accessible PDFs. For both image and text fields, you can specify an ExtendScript that runs after EasyCatalog populates the field.
Object Export Options
Note: Alt Text applies to image frames only.
The alternative text applied to the frame is defined using EasyCatalog’s Custom Field commands. For example, to use the contents of the My Alt Text field:
1 | FIELDSTR('My Alt Text') |
This is equivalent to selecting Object > Object Export Options > Custom as the Alt Text source in InDesign.
Post Population Script
For image fields, the script runs after the frame is populated. For text fields, it runs after the field is inserted or its content is updated.
The script receives the populated target in arguments[0]:
- Image field: the populated frame.
- Text field: the field’s text range, excluding EasyCatalog’s field markers.
Text post-population scripts run when content is inserted or changed. They do not run when an update leaves the content unchanged.
Without the Scripting Module:
1 2 | arguments[0] : The populated frame or field text range. arguments[1] : The document object. |
Example: Formatting an Image Frame
1 2 3 4 5 6 | var frame = arguments[0]; var doc = arguments[1]; frame.strokeColor = doc.swatches.itemByName("Red"); frame.strokeWeight = 5; frame.strokeAlignment = StrokeAlignment.CENTER_ALIGNMENT; |
Example: Formatting a Text Field
This example sets the first word to 24 points and the remaining text to 18 points. For Aperture Downlights, “Aperture” becomes 24pt and “Downlights” becomes 18pt:
1 2 3 4 5 6 7 | var text = arguments[0]; text.pointSize = 18; if (text.words.length > 0) { text.words[0].pointSize = 24; } |
With the Scripting Module installed:
Two additional arguments are supplied:
1 2 | arguments[2] : The DataSource object. arguments[3] : The Record object. |
This image-frame example reads the stroke weight from another field in the same record:
1 2 3 4 5 | var frame = arguments[0]; var record = arguments[3]; var stroke = record.fields.item("stroke weight"); frame.strokeWeight = Number(stroke.fieldContent); |
The Scripting Module also provides ecApplyProperties() on text objects. This applies EasyCatalog CSS-style property declarations:
1 2 3 4 5 6 7 | var text = arguments[0]; text.ecApplyProperties("pointSize: 18;"); if (text.words.length > 0) { text.words[0].ecApplyProperties("pointSize: 24;"); } |
Using a Script File
For more complex scripts, place a script file in the data source’s Scripts folder and reference it with an include directive:
1 | #include "applycolour.jsx" |
Example: Scaling a Barcode
This image-frame script enlarges the barcode content by 20% and centres it within its frame:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | var frame = arguments[0]; if (frame.pageItems.length > 0) { var innerFrame = frame.pageItems[0]; var bounds = innerFrame.geometricBounds; var currentWidth = bounds[3] - bounds[1]; var currentHeight = bounds[2] - bounds[0]; var resizeFactor = 1.2; var newWidth = currentWidth * resizeFactor; var newHeight = currentHeight * resizeFactor; innerFrame.geometricBounds = [ bounds[0], bounds[1], bounds[0] + newHeight, bounds[1] + newWidth ]; frame.fit(FitOptions.CENTER_CONTENT); } |
Script Errors
Errors from text post-population scripts are written to the EasyCatalog log with the prefix [POST POPULATION SCRIPT]. Logging must be enabled to record these errors.