5 Replies Latest reply on Oct 14, 2016 12:40 PM by Jasper de Fockert

    Retrieve the page number of a placed PDF

    Jasper de Fockert

      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

        • 1. Re: Retrieve the page number of a placed PDF
          S Hopkins Adobe Community Professional

          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[i];

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

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

               }

          }

          pageList

           

          Hope this helps.

          • 2. Re: Retrieve the page number of a placed PDF
            Laubender Adobe Community Professional & MVP

            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

            • 3. Re: Retrieve the page number of a placed PDF
              Kai Rübsamen Adobe Community Professional

              Uwe, this isn’t so complicated ;-)

               

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

               

              Kai

              • 4. Re: Retrieve the page number of a placed PDF
                Laubender Adobe Community Professional & MVP

                Hi Kai,

                you are so right.

                 

                I did not dig deep enough in the DOM documentation.

                 

                Best,
                Uwe

                • 5. Re: Retrieve the page number of a placed PDF
                  Jasper de Fockert Level 1

                  Hi Shirely, Uwe and Kai,

                   

                  Thank you so much for your quick and helpful responses. Indeed I was looking for the number of the placed PDF page.

                   

                  Pity I can only mark one correct answer .

                   

                  Have a good weekend!

                   

                  Regards,

                   

                  Jasper