9 Replies Latest reply on May 23, 2014 3:17 AM by markc0

    Another Javascript code

    markc0

      Hello

       

      I have Placed a PDF on a Layout in InDesign, I was Javascript to re-scale this to 117.7970

      I have found the code

      app.selection.horizontalScale=117.7970;

      app.selection.verticleScale=117.7970;

      But with this i have to select each image then this will apply, it would really like to use a foreach javascript loop so that if i have multiple PDF's placed on each page i can re-scale them all in one go.

      i mean the question would be how to use the above in a foreach loop for image placed PDF in the layout?

       

      Thanks

        • 1. Re: Another Javascript code
          Laubender Adobe Community Professional & MVP

          @Mark – you could loop through the allGraphics array of your document and check, if a graphic is of type PDF. But unfortunately this would also include placed Illustrator files.

           

          Alternatively we could loop through all the links in the links panel and check, if they are of type PDF and their names have the suffix *.pdf or *.PDF. That would exclude the Illustrator files.

           

          Once found a placed PDF we would ask for the parent of that link. That is the placed graphic. The parent of that parent will give us the container of the placed PDF page. Now we can decide what to scale: The container together with the graphic or the graphic inside the container.

           

          I'm not exactly sure what you'd like to scale. The container together with the placed graphic? Or the graphic inside the container?

           

          Uwe

          • 2. Re: Another Javascript code
            markc0 Level 1

            Sorry forgot to mention

            I would like to scale the placed graphic together with the container.

            It does not matter if there are illustrator files there as well

             

             

             

            Sent from my iPhone

            • 3. Re: Another Javascript code
              Laubender Adobe Community Professional & MVP

              @Mark – we already had something like that here not long ago.
              See the following script I posted a couple of weeks ago:

               

              Re: If Are all the pictures can be enlarged to 160% with script in indesign cs6?

               

              If you add an if statement to check for the value "Adobe PDF" of the property imageTypeName in the for-loop, you have solved your problem.

               

              Uwe

               

              //Edit:

              1. The script linked to will enlarge all graphics by the factor of 1.6. It will not enlarge all graphics to 160%.

              2. To edit the for loop you have to make the if-statement before scaling and check the variable myGraphics[n]:

               

              if(myGraphics[n].imageTypeName == "Adobe PDF"){
              
              // … myGraphicContainer.transform() … //
              
              }
              
              • 4. Re: Another Javascript code
                markc0 Level 1

                Many Thanks i now have the code as below

                However is there anyway to move the image to start where the top left margins start?

                As currently the image goes off the page

                 

                Thanks

                 

                 

                var arrayOfImages = app.activeDocument.allGraphics;

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

                var oneImage = arrayOfImages[i];

                if (oneImage.imageTypeName == "Adobe PDF"){

                 oneImage.horizontalScale = 123.1626;

                 oneImage.verticalScale = 123.1626;

                 oneImage.fit(FitOptions.frameToContent);

                   //oneImage.move(

                }

                 }

                • 5. Re: Re: Another Javascript code
                  Laubender Adobe Community Professional & MVP

                  @markc0 – alright, then you wanted to scale to a distinct percentage.

                  Moving the container frame after requiers the bounds of the pages.

                   

                  Here your code expanded:

                   

                  var arrayOfImages = app.activeDocument.allGraphics;
                  
                  for (i=0; i<arrayOfImages.length; i++){
                  
                      var oneImage = arrayOfImages[i];
                     
                      //Make sure, that:
                      //1. The graphic is of type "Adobe PDF"
                      //2. The graphic's container is not on the pasteboard
                     
                      if (oneImage.imageTypeName == "Adobe PDF" && oneImage.parent.getElements()[0].parentPage !== null){
                         
                          var currentPage = oneImage.parent.getElements()[0].parentPage;
                          var currentPageBounds = currentPage.bounds;
                          var upperLeft = [currentPageBounds[1],currentPageBounds[0]];
                         
                          //Could be locked? Then the following will throw an error:
                          //Unlock it then? Can it be unlocked? Or move to the next one?
                         
                          try{
                          oneImage.horizontalScale = 123.1626;
                          oneImage.verticalScale = 123.1626;
                  
                          oneImage.fit(FitOptions.frameToContent);
                  
                          oneImage.parent.move(upperLeft);
                         
                          }catch(e){
                              //Add error report here.
                              };
                  
                          };
                  
                      };
                  

                   

                   

                  Is it water tight? No.

                  It depends if a placed PDF was already scaled and how the Preferences for Scaling were set at that time.

                   

                  Uwe

                  • 6. Re: Another Javascript code
                    markc0 Level 1

                    wow thats great however this goes to the page bounds , but i only need it to go to the Margins

                     

                    i have only a top and a bottom margin both at 14.5px

                     

                    So how can i get it to go to the Margins instead of the top of the page page

                     

                    many Thanks

                    • 7. Re: Another Javascript code
                      markc0 Level 1

                      Hi UWE

                       

                      i think i have managed to work this out

                      this is what i have come up with

                      Many Thanks

                      Mark

                       

                      var arrayOfImages = app.activeDocument.allGraphics;

                       

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

                       

                          var oneImage = arrayOfImages[i];

                        

                          //Make sure, that:

                          //1. The graphic is of type "Adobe PDF"

                          //2. The graphic's container is not on the pasteboard

                        

                          if (oneImage.imageTypeName == "Adobe PDF" && oneImage.parent.getElements()[0].parentPage !== null){

                            

                              var currentPage = oneImage.parent.getElements()[0].parentPage;

                             var currentPageBounds = currentPage.bounds;

                             var marginBounds =

                             var upperLeft = [currentPageBounds[1],marginBounds[0]];

                              //Could be locked? Then the following will throw an error:

                              //Unlock it then? Can it be unlocked? Or move to the next one?

                            

                              try{

                              oneImage.horizontalScale = 123.1626;

                              oneImage.verticalScale = 123.1626;

                       

                              oneImage.fit(FitOptions.frameToContent);

                       

                              oneImage.parent.move(upperLeft);

                            

                              }catch(e){

                                  //Add error report here.

                                  };

                       

                              };

                       

                          };

                      • 8. Re: Another Javascript code
                        Laubender Adobe Community Professional & MVP

                        @Markc0 – sorry, I misread your demand. Thought of page bounds instead of margins.

                        Hm. In your code I cannot see where you defined the margins right…

                         

                        Is some code missing in your last post?

                         

                        Uwe

                        • 9. Re: Another Javascript code
                          markc0 Level 1

                          oh yes it missing for some reason

                           

                          here it is again

                           

                          var arrayOfImages = app.activeDocument.allGraphics;

                           

                           

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

                           

                           

                              var oneImage = arrayOfImages[i];

                            

                              //Make sure, that:

                              //1. The graphic is of type "Adobe PDF"

                              //2. The graphic's container is not on the pasteboard

                            

                              if (oneImage.imageTypeName == "Adobe PDF" && oneImage.parent.getElements()[0].parentPage !== null){

                                

                                  var currentPage = oneImage.parent.getElements()[0].parentPage;

                                 var currentPageBounds = currentPage.bounds;

                                 var marginBounds = [app.activeWindow.activePage.marginPreferences.top,app.activeWindow.activePage.marginPref erences.bottom]

                                 var upperLeft = [currentPageBounds[1],marginBounds[0]];

                                  //Could be locked? Then the following will throw an error:

                                  //Unlock it then? Can it be unlocked? Or move to the next one?

                                

                                  try{

                                  oneImage.horizontalScale = 123.1626;

                                  oneImage.verticalScale = 123.1626;

                           

                           

                                  oneImage.fit(FitOptions.frameToContent);

                           

                           

                                  oneImage.parent.move(upperLeft);

                                

                                  }catch(e){

                                      //Add error report here.

                                      };

                           

                           

                                  };

                           

                           

                              };