Change Overprint InDesign

Script for Adobe InDesign

Change the overprint of all elements, selected elements, or all on a selected layer.

  • Change fill or stroke or both
  • Set overprint on or off
  • Adapt open source to customize or create other scripts

For the Illustrator version of this script, see Change Overprint

Also see related script Color Layer Items InDesign

Download
Change Overprint InDesign

FREE to download
Please make a contribution

Many scripts are free to download thanks to the support of users. Help me keep developing new scripts by supporting my work. Click any one of the buttons below to make a contribution of any amount. Thank you.

× Stripe

Choose an amount to contribute.
Thank you for supporting my work.

How to use the script

The interface has two sections: Scope, and Overprint. Click the OK button and elements are modified as directed.

Section 1: Scope

All — every element throughout the document are affected.

Selected — only the currently selected elements are affected.

Layer — elements on the selected layer are affected. In the drop-down list, choose the desired layer.

Section 2: Overprint

Fill overprint — enable and select On or Off to change the fill overprint of elements. Disable and the fill overprint of all elements remains unchanged.

Stroke overprint — enable and select On or Off to change the stroke overprint of elements. Disable and the stroke overprint of all elements remains unchanged.

Regarding overprint

When told to overprint fill or stroke, and the item color is either zero percent CMYK or otherwise equivalent to “white” or “paper”, the script does not enable overprint, and when done, alerts the user “Items with no color (white) were not set to overprint.” This behavior is to prevent inadvertently overprinting white, which results in an invisible element once printed.

Source code

(download button below)

/*

Change Overprint InDesign
Copyright 2022 William Campbell
All Rights Reserved
https://www.marspremedia.com/contact

Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

*/

//@target indesign

(function () {

    var title = "Change Overprint InDesign";

    // Script variables.
    var doc;
    var error;
    var layerNames;
    var swatchNone;
    var warningWhite;

    // Reusable UI variables.
    var g; // group
    var gc1; // group (column)
    var gc2; // group (column)
    var p; // panel
    var w; // window

    // Permanent UI variables.
    var btnCancel;
    var btnOk;
    var cbOPFill;
    var cbOPStroke;
    var grpOPFill;
    var grpOPStroke;
    var listLayers;
    var rbAll;
    var rbLayer;
    var rbOPFillOff;
    var rbOPFillOn;
    var rbOPStrokeOff;
    var rbOPStrokeOn;
    var rbSelected;

    // SETUP

    // Script requires open document.
    if (!app.documents.length) {
        alert("Open a document", title, false);
        return;
    }
    doc = app.activeDocument;
    // Get layer names.
    layerNames = doc.layers.everyItem().name;
    swatchNone = doc.swatches[0];

    // CREATE USER INTERFACE

    w = new Window("dialog", title);
    w.alignChildren = "fill";
    // Panel.
    p = w.add("panel");
    p.alignChildren = "left";
    rbAll = p.add("radiobutton", undefined, "All");
    rbSelected = p.add("radiobutton", undefined, "Selected");
    g = p.add("group");
    g.alignment = "left";
    rbLayer = g.add("radiobutton", undefined, "Layer:");
    listLayers = g.add("dropdownlist", undefined, layerNames);
    listLayers.preferredSize = [150, -1];
    // Panel.
    p = w.add("panel");
    p.alignChildren = "left";
    // Group of 2 columns.
    g = p.add("group");
    // Groups, columns 1 and 2.
    gc1 = g.add("group");
    gc1.orientation = "column";
    gc1.alignChildren = "left";
    gc2 = g.add("group");
    gc2.orientation = "column";
    gc2.alignChildren = "left";
    // Rows.
    cbOPFill = gc1.add("checkbox", undefined, "Fill overprint:");
    grpOPFill = gc2.add("group");
    rbOPFillOn = grpOPFill.add("radiobutton", undefined, "On");
    rbOPFillOff = grpOPFill.add("radiobutton", undefined, "Off");
    cbOPStroke = gc1.add("checkbox", undefined, "Stroke overprint:");
    grpOPStroke = gc2.add("group");
    rbOPStrokeOn = grpOPStroke.add("radiobutton", undefined, "On");
    rbOPStrokeOff = grpOPStroke.add("radiobutton", undefined, "Off");
    // Action Buttons.
    g = w.add("group");
    g.alignment = "center";
    btnOk = g.add("button", undefined, "OK");
    btnCancel = g.add("button", undefined, "Cancel");
    // Panel Copyright.
    p = w.add("panel");
    p.add("statictext", undefined, "Copyright 2022 William Campbell");

    // SET DEFAULT VALUES
    // MUST PRECEDE UI EVENT HANDLERS SO THEY DON'T FIRE WHILE SETTING VALUES

    if (doc.selection.length) {
        rbSelected.value = true;
    } else {
        rbAll.value = true;
    }
    configureUi();

    // UI ELEMENT EVENT HANDLERS

    rbAll.onClick = function () {
        rbSelected.value = false;
        rbLayer.value = false;
        configureUi();
    };
    rbSelected.onClick = function () {
        rbAll.value = false;
        rbLayer.value = false;
        configureUi();
    };
    rbLayer.onClick = function () {
        rbAll.value = false;
        rbSelected.value = false;
        configureUi();
    };
    cbOPFill.onClick = configureUi;
    cbOPStroke.onClick = configureUi;

    btnOk.onClick = function () {
        if (rbLayer.value && !listLayers.selection) {
            alert("Select a layer", " ", false);
            return;
        }
        w.close(1);
    };

    btnCancel.onClick = function () {
        w.close(0);
    };

    // DISPLAY THE DIALOG

    if (w.show() == 1) {
        try {
            app.doScript(process, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, title);
            if (warningWhite) {
                alert("Items with no color (white) were not set to overprint");
            }
        } catch (e) {
            if (!error) error = e;
            alert("An error has occurred.\nLine " + error.line + ": " + error.message, title, true);
        }
    }

    //====================================================================
    //               END PROGRAM EXECUTION, BEGIN FUNCTIONS
    //====================================================================

    function colorItems(items) {
        var i;
        var item;
        var text;
        var vc = function (c) {
            // Validate object has property 'space'.
            return "space" in c;
        };
        for (i = 0; i < items.length; i++) {
            item = items[i];
            if (item.getElements()[0].constructor.name == "Group") {
                // Recurse (call self)
                colorItems(item.pageItems);
            } else {
                // Not a group
                if (item.getElements()[0].constructor.name == "TextFrame") {
                    // TEXT
                    text = item.texts[0];
                    // Fill
                    if (text.fillColor != swatchNone) {
                        // Fill overprint
                        if (cbOPFill.value && vc(text.fillColor)) {
                            if (rbOPFillOn.value && notWhite(text.fillColor, true)) {
                                text.overprintFill = true;
                            } else if (rbOPFillOff.value && notWhite(text.fillColor)) {
                                text.overprintFill = false;
                            }
                        }
                    }
                    // Stroke
                    if (text.strokeColor != swatchNone) {
                        // Stroke overprint
                        if (cbOPStroke.value && vc(text.strokeColor)) {
                            if (rbOPStrokeOn.value && notWhite(text.strokeColor, true)) {
                                text.overprintStroke = true;
                            } else if (rbOPStrokeOff.value && notWhite(text.strokeColor)) {
                                text.overprintStroke = false;
                            }
                        }
                    }
                }
                // ALL OTHER, NOT TEXT
                // Fill
                if (item.fillColor != swatchNone) {
                    // Fill overprint
                    if (cbOPFill.value && vc(item.fillColor)) {
                        if (rbOPFillOn.value && notWhite(item.fillColor, true)) {
                            item.overprintFill = true;
                        } else if (rbOPFillOff.value && notWhite(item.fillColor)) {
                            item.overprintFill = false;
                        }
                    }
                }
                // Stroke
                if (item.strokeColor != swatchNone) {
                    // Stroke overprint
                    if (cbOPStroke.value && vc(item.strokeColor)) {
                        if (rbOPStrokeOn.value && notWhite(item.strokeColor, true)) {
                            item.overprintStroke = true;
                        } else if (rbOPStrokeOff.value && notWhite(item.strokeColor)) {
                            item.overprintStroke = false;
                        }
                    }
                }
            }
        }
    }

    function configureUi() {
        if (!(rbAll.value || rbSelected.value || rbLayer.value)) {
            rbAll.value = true;
        }
        if (doc.selection.length) {
            rbSelected.enabled = true;
        } else {
            rbSelected.enabled = false;
        }
        listLayers.enabled = rbLayer.value;
        if (!(rbOPFillOn.value || rbOPFillOff.value)) {
            rbOPFillOn.value = true;
        }
        if (!(rbOPStrokeOn.value || rbOPStrokeOff.value)) {
            rbOPStrokeOn.value = true;
        }
        grpOPFill.enabled = cbOPFill.value;
        grpOPStroke.enabled = cbOPStroke.value;
    }

    function notWhite(color, warn) {
        if (
            "colorValue" in color && // MIXEDINK has no property 'colorValue'
            (
                color.colorValue.toString() == "0,0,0,0" || // CMYK
                color.colorValue.toString() == "255,255,255" || // RGB
                color.colorValue.toString() == "100,0,0" // Lab
            )
        ) {
            warningWhite |= warn;
            return false;
        }
        return true;
    }

    function process() {
        var layer;
        try {
            if (rbAll.value) {
                colorItems(doc.pageItems);
            } else if (rbSelected.value) {
                colorItems(doc.selection);
            } else if (rbLayer.value) {
                layer = doc.layers.itemByName(listLayers.selection.text);
                colorItems(layer.pageItems);
            }
        } catch (e) {
            error = e;
            throw e;
        }
    }

})();
× Stripe

Choose an amount to contribute.
Thank you for supporting my work.

Download
Change Overprint InDesign

License details included in download

For help installing scripts, see How to Install and Use Scripts in Adobe Creative Cloud Applications.

Also available for hire to program custom solutions. Contact William for more information.

IMPORTANT: by downloading any of the scripts on this page you agree that the software is provided without any warranty, express or implied. USE AT YOUR OWN RISK. Always make backups of important data.