1 Reply Latest reply on Jan 14, 2014 9:10 AM by Peter Spier

    Script for Place PDF file into a InDesign file

    walker85

      Hi everyone, i need to import a PDF file into a InDesign document and in order to do this i used scripts found over  the net (e.g. Zanelli's script ecc.) but i tried this solution:

       

      function(){
          app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
          var myDocument, myPage;
          if(app.documents.length != 0){
              myDocument = app.activeDocument;
          }
          else{
              alert("No document opened");
              exit();
          }
           if (app.selection[0] == undefined) {
              alert("Select box");
              exit();
           } else {
                  var myPDFFile = File.openDialog("Select PDF:");
                  if((myPDFFile != "")&&(myPDFFile != null)){ 
                      myDocument.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;
                      myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS;
                      myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;    
                      var myData = new Array;
                      myData[0] = app.selection[0].parentPage;
                      myData[1] = app.selection[0].geometricBounds;
                      myData[2] = app.selection[0];
                      myPlacePDF(myDocument, myData, myPDFFile);
                }      
           }
      
          //FUNCTIONS
          function myPlacePDF(myDocument, myData, myPDFFile){
              var myPDFPage;
              var myPage = myData[0];
              var myGeometricBounds = myData[1].toString().split(",");
              app.pdfPlacePreferences.pdfCrop = PDFCrop.cropMedia;
              var myCounter = 1;
              var myBreak = false;
              while(myBreak == false){
                  if(myCounter > 1){
                      myPage = myDocument.pages.add(LocationOptions.after, myPage);
                  }          
                   app.pdfPlacePreferences.pageNumber = myCounter;
                   myRectangle = myPage.rectangles.add(undefined, undefined, undefined, {geometricBounds:[myGeometricBounds[0],myGeometricBounds[1],myGeometricBounds[2],myGeometricBounds[3]]});
                   myRectangle.clearFrameFittingOptions();   
                   myRectangle.frameFittingOptions.fittingOnEmptyFrame = EmptyFrameFittingOptions.PROPORTIONALLY;
                   myRectangle.frameFittingOptions.autoFit = true;
                   myRectangle.frameFittingOptions.fittingAlignment = AnchorPoint.CENTER_ANCHOR;
                   myPDFPage = myRectangle.place(File(myPDFFile), false)[0];            
                   if(myCounter == 1){
                      var myFirstPage = myPDFPage.pdfAttributes.pageNumber;
                  }
                  else{
                      if(myPDFPage.pdfAttributes.pageNumber == myFirstPage){
                          myPage.remove();
                          myBreak = true;
                      }
                  }
                  myCounter = myCounter + 1;
              }
               myData[2].remove();   
          }
      }
      
      

       

       

      what i would is, before the script place every single page of PDF file in the document, determine if the same page of the Pdf file is vertical or horizontal, to make the right section for the page.

      Is it possible?
      Thank you