Skip to main content
Indian Aviation Art
Participant
Nov 19, 2026 4:36 PM UTC
Question

Is there a way to detect mismatched chapter headings and Table of Contents entries before exporting a book for print?

Hi everyone,

I recently ran into an issue while preparing a book for print. Just before the final export, the client requested a change to one of the chapter headings. I made the correction but forgot to update the corresponding entry in the Table of Contents. Unfortunately, we discovered the mismatch only after the book had gone to print.

This got me thinking: Wouldn't it be useful if InDesign could automatically detect when the Table of Contents is out of sync with the actual headings in the document?

It would be great to have this check integrated into the Preflight panel. Whenever a heading is modified, added or removed after generating the TOC, InDesign could flag it with a warning such as Table of Contents needs to be updated.

I understand that InDesign already allows us to generate and update TOCs, but having an automated validation check before exporting could prevent such oversights, especially when working with lengthy books and complex publications.

Does anything like this already exist, or would this be a useful addition to InDesign?

    3 replies

    Mike Witherell
    Community Expert
    Community Expert
    Nov 19, 2026 7:03 PM UTC

    Here is an ExtendScript JavaScript that works in InDesign 2027 and triggers if you do a File > Package or an Export (to PDF or anything).

    #targetengine "tocExportPackageEngine"

    (function () {
    // 1. Attach to File > Package...
    attachMenuListener("$ID/Package...", "tocBeforePackage", "packaging");

    // 2. Attach to File > Export... (catches Interactive PDF, Print PDF, etc.)
    attachMenuListener("$ID/Export...", "tocBeforeExport", "exporting");

    function attachMenuListener(menuKey, listenerName, actionLabel) {
    var menuAction = app.menuActions.itemByName(menuKey);
    if (!menuAction.isValid) return;

    var existing = menuAction.eventListeners.itemByName(listenerName);
    if (existing.isValid) existing.remove();

    menuAction.addEventListener("beforeInvoke", function () {
    if (app.documents.length === 0) return;
    checkAndPromptTOC(app.activeDocument, actionLabel);
    }).name = listenerName;
    }

    function checkAndPromptTOC(doc, actionLabel) {
    var tocStory = findTOCStory(doc);
    if (!tocStory) return; // No TOC found in document

    var response = confirm(
    "A Table of Contents was detected in this document.\nDo you want to update it before " + actionLabel + "?",
    false,
    "Update Table of Contents?"
    );

    if (response) {
    updateTOCStory(doc, tocStory);
    }
    }

    // Detects TOC stories via saved TOC Styles OR default "TOC" paragraph styles
    function findTOCStory(doc) {
    var tocStyleIds = {};

    // Check all saved TOC styles (index 1+)
    for (var i = 1; i < doc.tocStyles.length; i++) {
    var ts = doc.tocStyles[i];
    if (ts.titleStyle && ts.titleStyle.isValid) {
    tocStyleIds[ts.titleStyle.id] = true;
    }
    for (var j = 0; j < ts.tocStyleEntries.length; j++) {
    var fStyle = ts.tocStyleEntries[j].formatStyle;
    if (fStyle && fStyle.isValid) {
    tocStyleIds[fStyle.id] = true;
    }
    }
    }

    // Scan stories for matching TOC styles OR default "TOC title" / "TOC body text" styles
    for (var s = 0; s < doc.stories.length; s++) {
    var story = doc.stories[s];
    if (story.paragraphs.length === 0) continue;

    var checkCount = Math.min(story.paragraphs.length, 3);
    for (var p = 0; p < checkCount; p++) {
    var pStyle = story.paragraphs[p].appliedParagraphStyle;
    if (tocStyleIds[pStyle.id] || /^TOC\b/i.test(pStyle.name)) {
    return story;
    }
    }
    }
    return null;
    }

    // Selects the TOC frame and triggers InDesign's native Update Table of Contents
    function updateTOCStory(doc, tocStory) {
    var originalSelection = app.selection;
    var originalTool = app.toolBoxTools.currentTool;

    try {
    if (tocStory.textContainers.length === 0) {
    alert("TOC frame could not be located.");
    return;
    }

    // Place text insertion point inside the TOC story so "Update Table of Contents" enables
    app.select(tocStory.insertionPoints[0]);

    var updateAction = app.menuActions.itemByName("$ID/Update Table of Contents");
    if (updateAction.isValid && updateAction.enabled) {
    updateAction.invoke();
    alert("Table of Contents has been updated.", "TOC Updated");
    } else {
    alert("Could not run 'Update Table of Contents' (menu item was disabled). Please update manually via Layout > Update Table of Contents.");
    }
    } catch (e) {
    alert("TOC Update Error: " + e.message);
    } finally {
    // Restore original selection and tool
    try {
    app.select(originalSelection);
    app.toolBoxTools.currentTool = originalTool;
    } catch (restoreErr) {}
    }
    }
    })();

     

    Translate
    Mike Witherell
    Mike Witherell
    Community Expert
    Community Expert
    Nov 19, 2026 6:40 PM UTC
    CORCTON34033231
    Community Expert
    Community Expert
    Nov 19, 2026 6:05 PM UTC

    Hi, unfortunately there’s no built-in check like that — InDesign doesn’t flag an out-of-date TOC in Preflight, and a TOC doesn’t update itself when a heading changes. The reliable safeguard before export is to update it manually: click into the TOC text frame, then go to Layout > Update Table of Contents. For a book, update the TOC in each document (the Book panel can update the whole book), and check that the heading paragraph styles are the ones included in your TOC Style, so the update picks up every change. Adobe’s help page explains this here: https://helpx.adobe.com/indesign/desktop/indexes-and-references/add-a-table-of-contents/generate-maintain-tocs.html Your Preflight idea is a good one — worth posting as a Feature Request so others can vote for it.

    Translate