Scripting InDesign CS4 Preflight

We’ve received numerous requests for sample scripts that demonstrate working with the Adobe InDesign CS4 new live preflight feature. Several of these requests have come from InDesign Server partners who want to know how to use the new preflight engine. My Creative Suite Developer Technologies teammate Joe Stinson and I collaborated on the following information that we think will save you a lot of time when trying to script the new preflight feature.

If you are not familiar with preflight, please first watch this introductory video:

This post will demonstrate how to interact with the preflight system using JavaScript. For illustration purposes, we show how to configure preflight to raise an error if the page size is something other than letter size (8.5”X 11”). We briefly highlight how it’s done in the UI, then show how to achieve the same results through scripting.

Importing a Preflight Profile

You can import a preflight profile through the Preflight Panel in InDesign: choose Preflight Panel > Define Profiles, then choose Load Profile from the drop-down menu in the Preflight Profiles window.

Load Profiles

You also can load a profile with scripting.  The following JavaScript imports a profile called Test.idpp:

var profile = app.loadPreflightProfile(File("/c/Test.idpp"));

//If a profile was not loaded
if (profile == null)
    alert("The profile did not load successfully");

It’s easier to create profiles using the Preflight Panel than with scripting.  One workflow would be to create all profiles in the UI, export them to files, and import them using scripting.  This approach avoids the challenges involved with manually adding rules via JavaScript.

Creating a Profile

To create a preflight profile from the Preflight Panel, choose Preflight Panel > Define Profiles, then choose the plus sign (+) to add a new preflight profile.  Name the profile and fill in all data values for the available rules.

Define Profiles

You also can create a profile with scripting.  The following adds a single profile called Test:

//add profile
var profile = app.preflightProfiles.add(); = "Test";
profile.description = "Test description";

Preflight-profile names must be unique.  If the script above is executed more than once within the same InDesign instance, an error is raised, indicating that a profile with that name already exists.  To avoid this, either access the existing profile using app.preflightProfiles.itemByName(), or check to see if a profile exists and remove it as follows:

function removeProfile(name)
    //Lookup the existing Preflight Profile by name
    var oldProfile = app.preflightProfiles.itemByName(name);
    //If a profile with that name was found
    if (oldProfile != null)

Adding Rules

A preflight profile contains a mutually exclusive set of rules.  To add a rule to a profile, follow these steps:

  1. Add a rule to a profile by name.
  2. Set the rule’s data values.
  3. Set the rule’s reporting state.

Each step is described below.

1. Add a rule to a profile by name.Rules are added by name.   For information on rule names, see “Available Rules.”  The following adds the ADBE_PageSizeOrientation rule to the profile:

//Add a rule that requires a specific page size and orientation (Portrait or Landscape).
const RULE_NAME = "ADBE_PageSizeOrientation";
var rule = profile.preflightProfileRules.add(RULE_NAME);

2. Set the rule’s data values.Many, but not all, rules have data properties.  For a complete specification of the rules available with InDesign CS4, see “Available Rules.”  The ADBE_PageSizeOrientation rule contains particular data properties that allow you to specify a page size.  The following sets the acceptable page height and width, a tolerance (fudge factor), and an option for handling page orientation:

//Requires the page size to be 8.5 in x 11in (Letter Size)
//enters a value for tolerance
rule.ruleDataObjects.add("tolerance", RuleDataType.realDataType, 0.01);

//Sets the width  to the point equivalent of 8.5 inches
rule.ruleDataObjects.add("width", RuleDataType.realDataType, 612);

// Sets the width  to the point equivalent of 11 inches
rule.ruleDataObjects.add("height", RuleDataType.realDataType, 792);

//true = ignore orientation is checked
rule.ruleDataObjects.add("ignore_orientation", RuleDataType.booleanDataType, true);

3. Set the rule’s reporting state.This is done using the rule’s flag property.  There are several choices (disabled, information, warning, and error), controlled by the PreflightRuleFlag enumeration:

//set the rule to return an error
rule.flag = PreflightRuleFlag.returnAsError;

Processing a Profile

In the desktop version of InDesign, preflight errors are reported in the UI.  In scripting (especially for InDesign Server), the errors are generated on demand.  The following script processes an InDesign document.  If there are errors, it writes the results to a new PDF file.  For an example of the output, see the figure below the example.

//Process the doc with the rule
var process = app.preflightProcesses.add(doc, profile);
results = process.processResults;

//If Errors were found
if (results != ‘None’)
    //Export the file to PDF
    //The “true” value selects to open the file after export.
    process.saveReport(File("/c/PreflightResults.pdf"), true);


Preflight Report

If you would rather produce a text file, simply name your output file with a .txt extension.
Alternately, you may prefer to iterate the errors yourself.  The following demonstrates how to access the errors array:

//array containing detailed results
errors = process.aggregatedResults;

Custom Rules

It is not possible to create custom rules through the Preflight Panel or scripting; however, this can be done through a C++ plug-in.  The InDesign CS4 Products SDK contains a sample, PreflightRule, that demonstrates how to add custom rules with a plug-in.

Available Rules

One of the hardest aspects about scripting rules is discovering rule names and properties.  Due to the dynamic nature of rules (they really are just strings), specific rule names and properties do not show up in the Extend Script Tool Kit’s Object Model Viewer.  There are a couple ways to discover this information.  For your convenience, we’ve written a script that produces the following output.  This script (dumpLivePreflightRules.jsx) will be added to a future version of the SDK.  If you use a plug-in that adds custom rules, you’ll need to run the script to extract the new names and properties.

Rule Name Rule Properties
ADBE_BlankPages yes
ADBE_BleedSlug yes
ADBE_BleedTrimHazard yes
ADBE_CMYPlates no
ADBE_Colorspace yes
ADBE_ConditionIndicators no
ADBE_CrossReferences yes
ADBE_FontUsage yes
ADBE_ImageColorManagement yes
ADBE_ImageResolution yes
ADBE_InteractiveContent no
ADBE_LayerVisibility no
ADBE_MissingFonts no
ADBE_MissingGlyph no
ADBE_MissingModifiedGraphics no
ADBE_Overprint no
ADBE_OversetText no
ADBE_PageCount yes
ADBE_PageSizeOrientation yes
ADBE_Registration no
ADBE_ScaledGraphics yes
ADBE_ScaledType yes
ADBE_SmallText yes
ADBE_SpellCheck no
ADBE_SpotColorSetup yes
ADBE_StrokeRequirements yes
ADBE_TextOverrides yes
ADBE_TransparencyBlending yes
ADBE_TransparencyUsage no
ADBE_WhiteOverprint no


Data Type Name Default Value
Boolean ignore_master true
Boolean ignore_nonprinting true


Data Type Name Default Value
Real bleed_b 9
Real bleed_b_aux 9
Integer bleed_comparison_type 3
Boolean bleed_enabled true
Real bleed_l 9
Real bleed_l_aux 9
Real bleed_r 9
Real bleed_r_aux 9
Real bleed_t 9
Real bleed_t_aux 9
Real slug_b 18
Real slug_b_aux 18
Integer slug_comparison_type 3
Boolean slug_enabled false
Real slug_l 18
Real slug_l_aux 18
Real slug_r 18
Real slug_r_aux 18
Real slug_t 18
Real slug_t_aux 18
Real tolerance 0.01


Data Type Name Default Value
Boolean binding_enabled false
Real binding_width 1
Real live_b 18
Real live_l 18
Real live_r 18
Real live_t 18
Real tolerance 0.01


Data Type Name Default Value
Boolean no_cmyk false
Boolean no_gray false
Boolean no_lab false
Boolean no_rgb false
Boolean no_spot false


Data Type Name Default Value
Boolean xrefs_out_of_date true
Boolean xrefs_unresolved true


Data Type Name Default Value
Boolean no_ATC false
Boolean no_Bitmap false
Boolean no_CID false
Boolean no_MultipleMaster false
Boolean no_OpenTypeCFF false
Boolean no_OpenTypeCID false
Boolean no_OpenTypeTT false
Boolean no_TrueType false
Boolean no_Type1 false
Boolean no_protected true


Data Type Name Default Value
Boolean no_cmyk_profiles true
Boolean no_image_overrides true
Boolean overrides_exclude_uncal true


Data Type Name Default Value
Boolean bw_max_enabled false
Real bw_max_res 2400
Boolean bw_min_enabled true
Real bw_min_res 800
Boolean color_max_enabled false
Real color_max_res 1200
Boolean color_min_enabled true
Real color_min_res 250
Boolean gray_max_enabled false
Real gray_max_res 1200
Boolean gray_min_enabled true
Real gray_min_res 250
Real tolerance 0.5


Data Type Name Default Value
Integer comparison_type 2
Integer comparison_value 1
Integer comparison_value_aux 1


Data Type Name Default Value
Real height 792
Boolean ignore_orientation false
Real tolerance 0.01
Real width 612


Data Type Name Default Value
Real max_scale 100.5


Data Type Name Default Value
Boolean ignore_justification true
Real max_scale 100.5


Data Type Name Default Value
Real minSize 4
Boolean minSize_trap_safe_only false


Data Type Name Default Value
Boolean lab_spots true
Boolean lab_spots_enabled false
Integer max_spots 1
Boolean max_spots_enabled true


Data Type Name Default Value
Real min_width 0.125
Boolean min_width_trap_safe_only false


Data Type Name Default Value
Boolean ignore_color_overrides false
Boolean ignore_font_overrides false
Boolean ignore_kerning_tracking_overrides false
Boolean ignore_language_overrides false


Data Type Name Default Value
Integer space 3

Comments are closed.