Skip to main content
Participant
October 14, 2016
Answered

Retrieve the page number of a placed PDF

  • October 14, 2016
  • 2 replies
  • 872 views

Hi all,

This seems to be impossible but has anybody managed or has any idea how to achieve it?

The information is visible in the links panel, but I have no idea how to retrieve it using extend script.

Thank you in advance for any help you can offer.

Regards,

Jasper

This topic has been closed for replies.
Correct answer Kai Rübsamen

Uwe, this isn’t so complicated ;-)

app.selection[0].graphics[0].pdfAttributes.pageNumber;

Kai

2 replies

Community Expert
October 14, 2016

Hi Jasper,

interesting question.

I have no answer other than to export the frame holding the PDF to IDMS and inspect the IDMS file.

Just did that and the text of IDMS contains a line like that:

<PDFAttribute PageNumber="8" PDFCrop="CropMedia" TransparentBackground="true" />

And there you have all relevant attributes.
PageNumber is "8", I have placed the 8th page of my PDF.
PDFCrop is "CropMedia" just like I wanted it and the Background is set to transparent.

Shirely,

I think, Jasper is asking about the name of the placed PDF page and not the name of the page the PDF is placed.

Regards,
Uwe

Kai Rübsamen
Kai RübsamenCorrect answer
Participating Frequently
October 14, 2016

Uwe, this isn’t so complicated ;-)

app.selection[0].graphics[0].pdfAttributes.pageNumber;

Kai

Community Expert
October 14, 2016

Hi Kai,

you are so right.

I did not dig deep enough in the DOM documentation.

Best,
Uwe

Inspiring
October 14, 2016

Hi,

The problem with PDFs and other placed page items is that they are usually contained by another page item.

To answer your question, the problem remains in how your placed PDF is being referenced (is it selected? or a member of a list of items?). Here are some ideas.

If you have a selection you need to determine if the selected item is the PDF or the container of the PDF.

--AppleScript: returns page name of page for selection

tell application "Adobe InDesign CC 2015"

  set selList to selection

  set selItem to item 1 of selList

  if class of selItem is PDF then

  set myContainer to parent of selItem

  else

  set myContainer to selItem

  end if

  set myPage to name of parent page of myContainer

end tell

--ExtendScript: returns name of page for selection

var selList = app.selection;

var selItem = selList[0];

var containerRef;

if (selItem.constructor.name == "rectangle") {

    containerRef = selItem;

} else {

    containerRef = selItem.parent;

}

var pageRef = containerRef.parentPage.name;

pageRef;

If you are getting the reference to the PDF through the collection of links within the document you can

get a list of every link of the document that is PDF and then get the parent page of its parent:

--Applescript: returns list of page numbers of pages having a link type of PDF

set pageList to {}

tell application "Adobe InDesign CC 2015"

  tell document 1

  set x to every link where link type of it is "Adobe Portable Document Format (PDF)"

  repeat with i from 1 to length of x

  set z to parent page of parent of item i of x

  set end of pageList to name of z

  end repeat

  end tell

end tell

pageList

--ExtendScript: returns list of page numbers of pages having a link type of PDF

var pageList = [];

var docRef = app.documents.item(0);

var linkList = docRef.links;

var thisLink;

for (var i = 0; i < linkList.length; i++) {

    thisLink = linkList;

    if (thisLink.linkType == "Adobe Portable Document Format (PDF)") {

        pageList.push(thisLink.parent.parentPage.name);

     }

}

pageList

Hope this helps.