Skip to main content
Participant
March 27, 2026
Answered

Update the linked PDFs page with JSX script

  • March 27, 2026
  • 1 reply
  • 24 views

I’m writing an InDesign script using JSX. I want to loop through all frames and check if they have specific script labels set, which I then want to use to change the page of the linked PDF file. I can do all the steps outside the last one.

 

How to use a JSX script to update a frame’s linked PDF’s page?

var allframes = app.activeDocument.allPageItems;

for (i = 0; i < allframes.length; i++) {
// Pseudo code of the part I need help with:
allframes[i].updateImportedPage(4)
}

 

    Correct answer samil40909655

    Thank you for your answer. However, the pageNumber is a read only property. I had to place the PDF again to circumvent this.

     

    // Original PDF file
    var file = graphic.itemLink.filePath;

    //Set placement preference (ie. the )
    app.pdfPlacePreferences.pageNumber = newPage;

    // Replace the PDF file with new page
    graphic.parent.place(File(file));

     

    1 reply

    Community Expert
    March 28, 2026

    I don’t think (or I haven’t found it) that InDesign exposes updateImportedPage() on page items. I think in placed PDFs, the page number is controlled through the PDF attributes of the graphic inside the frame, not the frame itself.

    So what I have seen in other scripts:

    • Check the frame contains a placed PDF
    • Access the graphic inside the frame
    • Modify its pdfAttributes.pageNumber
    • Then reassign or relink if needed (usually not necessary)

    For example:

    var doc = app.activeDocument;
    var allItems = doc.allPageItems;

    for (var i = 0; i < allItems.length; i++) {
    var item = allItems[i];

    // Check it’s a rectangle/image frame with a graphic
    if (item.graphics && item.graphics.length > 0) {
    var graphic = item.graphics[0];

    // Check it's a placed PDF
    if (graphic.constructor.name === "PDF") {

    // Optional: check for your script label
    if (item.label === "yourLabelHere") {

    try {
    // Change the page number
    graphic.pdfAttributes.pageNumber = 4;

    } catch (e) {
    $.writeln("Error on item " + i + ": " + e);
    }
    }
    }
    }
    }

     

    • item.graphics[0] is the actual placed asset.
    • pdfAttributes.pageNumber is the property you need.

    This works without relinking InDesign updates the display automatically.
    If nothing happens, the PDF might not actually be a PDF object (e.g. EPS or AI), so log graphic.constructor.name to confirm.

    If you want to drive page numbers dynamically (e.g. from the label) the something like the below:

    var targetPage = parseInt(item.label, 10);
    if (!isNaN(targetPage)) {
    graphic.pdfAttributes.pageNumber = targetPage;
    }

    If your labels are more complex (like page=4), you’ll need to parse that string before applying it.

    If this still doesn’t update in your case, it’s usually because the link is cached, in that scenario, forcing a relink with the same file can help, but in most cases the property change alone is sufficient.

    I’ve a few PDF relinking scripts I’ve done myself. And help from a few scripters over the years to improve them. Happy to share those relink scripts.

     

    One I have is to import the PDF and choose the bounding box before placing - then places it centered on the page and changes the blend mode - it can do 1 or more pages. 

    And the other is to simply update the placed pdf if it’s Page 1 - it switches it to Page 2. 
    Happy to share if you think they’ll be of use. 


    And there is this https://creativepro.com/script-show-options-files/ 

    Might help you disect some scripting logic. 

     

     

    samil40909655AuthorCorrect answer
    Participant
    March 28, 2026

    Thank you for your answer. However, the pageNumber is a read only property. I had to place the PDF again to circumvent this.

     

    // Original PDF file
    var file = graphic.itemLink.filePath;

    //Set placement preference (ie. the )
    app.pdfPlacePreferences.pageNumber = newPage;

    // Replace the PDF file with new page
    graphic.parent.place(File(file));

     

    Community Expert
    March 28, 2026

    Cool, that confrims that you have to force the relink.