2 Replies Latest reply on Jan 19, 2010 4:26 PM by Yuliaart

    To place specific pdf page into InDesign CS4 JS

    Yuliaart Level 1

      Hi, I need to place second page of pdf file into second page of InDesign, or place nothing if there is no second page in the pdf. The script that I have so far places first pdf page when can't find second. How can I avoid that:

       


      function myPlacePDF(myDocument, myFile){

       

          app.pdfPlacePreferences.pdfCrop = PDFCrop.cropMedia;           
          myPage = myDocument.pages[1];  //place file on the second page of InDesign
          app.pdfPlacePreferences.pageNumber = 2; // Place second page of the pdf
          myPDFPage = myPage.place(File(myFile), [0,0])[0];

          app.pdfPlacePreferences.pageNumber = 1;
          }

       

       

      The other thing about it that I would like to modify is: I would prefer no to use pdfPreferences to assign the page number to place, so I don't have to reset it later, but when I try pdfAttributes line, it doesn't work for some reason:

       

       

          var myFileAR = myFolder.getFiles ("back_*");
          var myFilePath = myFileAR[0];
          var myFile = File (myFilePath);

          myFile.PDFAttribute.pageNumber = 2;

       

      Your help is highly appreciated.

       

      Yulia

        • 1. Re: To place specific pdf page into InDesign CS4 JS
          [Jongware] Most Valuable Participant

          This setting

           

          app.pdfPlacePreferences.pageNumber = 2;

           

          is only used while importing the file. You cannot change it afterwards (more exact: it will be used, but only for the next PDF you place).

          As it seems ID silently uses page #1 if your requested page number is out of range for the PDF, all you can do is test the actually placed page number after placing the PDF:

           

          if (myPDFPage.pdfAttributes.pageNumber != 2)

             myPDFPage.parent.remove();

           

          Notice the "parent" here. Removing just the PDF page will leave an empty frame. Removing the parent frame will also remove the image itself.

           

          [Ed.] The ESTK Help on PDFAttribute answers the second half of your question. "pageNumber" is a read-only property.

          • 2. Re: To place specific pdf page into InDesign CS4 JS
            Yuliaart Level 1

            That's perfect, thank you so much.

             

            Yulia