Skip to main content
Legend
July 31, 2025
Answered

How to get the current page index of a pdf/ai placed as a PlacedItem via ExtendScript

  • July 31, 2025
  • 3 replies
  • 573 views

A pdf/ai can have multiple pages, and when placing it, the user specifies the target page (if not specified, it defaults to 1).

 

So, is there a way to determine the page of a pdf/ai file that has already been placed as a PlacedItem within a document?

 

I know there is no direct property to express this. In other words, I am looking for either a workaround method like embedding it first and then examining the PageItem structure, or an unexpected method that elegantly solves this problem.

 

Similar posts

Correct answer CarlosCanto

Here you go, select your placed pdf before running

 

// Elegant solution to get selected linked PDF item's page number
selection[0].relink(selection[0].file);
var currentPage = app.preferences.getIntegerPreference ("plugin/PDFImport/PageNumber");
alert("Current page number: " + currentPage);

 

 

3 replies

sttk3Author
Legend
August 7, 2025

There was an object that was more accessible in the script for getting the current page number.

var currentPage = app.preferences.PDFFileOptions.pageToOpen ;
CarlosCanto
Community Expert
CarlosCantoCommunity ExpertCorrect answer
Community Expert
August 1, 2025

Here you go, select your placed pdf before running

 

// Elegant solution to get selected linked PDF item's page number
selection[0].relink(selection[0].file);
var currentPage = app.preferences.getIntegerPreference ("plugin/PDFImport/PageNumber");
alert("Current page number: " + currentPage);

 

 

m1b
Community Expert
Community Expert
August 1, 2025

Carlos you absolute LEGEND!!  😄

CarlosCanto
Community Expert
Community Expert
August 1, 2025

😁

m1b
Community Expert
Community Expert
July 31, 2025

Hi @sttk3 sadly I don't know of any way to do this, so I will be watching this question.

 

I can imagine a very hacky approach that might work in most cases. The script would:

1. export the placed image as svg (with a known position and matrix).

2. place each page of the pdf (give it the same position and matrix) and export as svg.

3. compare 1 with 2 until you find a match (I'm hoping there might be a good place to look for a match, rather than byte-by-byte).

 

I'm sorry for how terrible that is, but it's all I can think of. I will wait to see if anyone has any good ideas.

- Mark

sttk3Author
Legend
July 31, 2025

Thank you for your idea. At the moment, the only method I can think of is the messy one that we have suggested. I wish there were a simpler way.