Quickly change the Page Number in a Linked PDF via InDesign Script

Are you tired of relinking PDF files just to change a page number, only to need to find the folder the file originally at again? Afterward, you forget to click the “Show Import Options”, so you have to do the whole process again? Ah, the joys of Adobe’s usability and user experience…

Don’t fret though! With this script, all you need to do is select the graphic, double-click the script, and enter a page number, It will magically change to the page number you want!

Setup

  1. In InDesign, open the Scripts panel in Window > Utilities > Scripts (or Ctrl+Alt+F11)
  2. Right-click the User folder, and select Reveal in Explorer.
  3. Create a new file called ChangePDFPage.jsx with the following code:
"use strict";
function main() {
    const selection = app.selection[0];
    if (!selection)
        return;
    if (!(selection instanceof Rectangle))
        return;
    const graphic = selection.graphics[0];
    if (!graphic)
        return;
    if (!(graphic instanceof Graphic))
        return;
    const filePath = graphic.itemLink.filePath;
    const link = graphic.itemLink;
    const pdf = link.parent;
    const pageNumber = pdf.pdfAttributes.pageNumber;
    const chosenPage = parseInt(prompt("Choose Page Number:", pageNumber.toString()));
    if (isNaN(chosenPage)) {
        alert("Invalid page number");
        return
    }
    app.pdfPlacePreferences.pageNumber = chosenPage;
    graphic.place(filePath, false);
}
function propertiesToString(properties) {
    var s = "";
    for (var i in properties) {
        s += i + " " + properties[i] + "\n";
    }
    return s;
}
main();

Usage

  1. Select a linked PDF on the page.
  2. Double-click on the ChangePDFPage.jsx in the Scripts panel.
  3. Input a page number, and press Enter.
  4. Profit!

Final Remarks

This script can probably be slightly adjusted to work in Adobe Illustrator. If anybody is interested, drop a comment and I can publish the code for that as well.

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.