Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Enthusiast ,
Jul 31, 2025 Jul 31, 2025

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

TOPICS
Import and export , Scripting
385
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 31, 2025 Jul 31, 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);

 

 

Translate
Adobe
Community Expert ,
Jul 31, 2025 Jul 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 31, 2025 Jul 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 31, 2025 Jul 31, 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);

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 01, 2025 Aug 01, 2025

Carlos you absolute LEGEND!!  😄

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 01, 2025 Aug 01, 2025

😁

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Aug 01, 2025 Aug 01, 2025

Wonderful! You are now at the forefront of humanity!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 01, 2025 Aug 01, 2025
quote

Wonderful! You are now at the forefront of humanity!


By @sttk3

 

that's a bit much Lol

but thanks for the nomination 😂

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 01, 2025 Aug 01, 2025

By the way, Carlos, I have a script I use a lot—it justs switches pages of placed .ai files. Now with your method to get the page number, I've made that script work better (no need to type in the page I wanted). FYI I've just put the script here.

- Mark

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 01, 2025 Aug 01, 2025

wow nice application of the concept!! I like simple, effective scripts

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Aug 06, 2025 Aug 06, 2025
LATEST

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

var currentPage = app.preferences.PDFFileOptions.pageToOpen ;
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines