3 Replies Latest reply on Jun 12, 2015 11:24 AM by KenWK

    Get the objects on a page or get the selection with JavaScript?

    KenWK Level 1

      I have a bunch of single page PDFs with an ornament on the page. I need to crop all of the pages the same distance from the ornament. The problem comes that the ornament is never in the same horizontal position.

       

      I have the script down to where the operator crops the page tight to the ornament and I'm using getPageBox and setPageBox to then expand the crop evenly around the whole page, but I'd like to automate this completely.

       

      Essentially I need a way to know where the ornament is on the page. Is there a way in Java (I couldn't find one) to iterate through the objects on the page to check their size?

       

      Many thanks,

      Ken

        • 1. Re: Get the objects on a page or get the selection with JavaScript?
          try67 MVP & Adobe Community Professional

          Not possible with JavaScript.

          • 2. Re: Get the objects on a page or get the selection with JavaScript?
            KenWK Level 1

            Thanks try.

             

            OK, so I've come down to having the operator use the "Edit Text & Images" tool to select all, then hold the shift key and lasso around the ornament to DE-select it and everything inside of it, then delete everything else.

             

            An Action then crops the white space and runs JavaScript to set the page boxes to the correct size. However, the Trim and Bleed boxes won't change from the "Remove Whie Margins" crop that is implemented in the action. The Crop and Art boxes change, but no matter what order I do things it the Trim and Bleed boxes won't.

             

            The Java code is below. Any help would be greatly apprecaited.

            var TargetWid=302

            var TargetHt=477

            // Get the crop box for the page

            var CurrRect = this.getPageBox({cBox:"Crop", nPage:0});

            var AdjWid = (TargetWid-CurrRect[2])/2

            var AdjHt = (TargetHt-CurrRect[1])/2

            //debugging lines start

            //app.alert(CurrRect[0]);

            //app.alert(CurrRect[1]);

            //app.alert(CurrRect[2]);

            //app.alert(CurrRect[3]);

            //app.alert(AdjWid);

            //debugging lines end

            // Set the new crop area of the box (in pixels)

            CurrRect[0] -= AdjWid;  // Adjust Left Side

            CurrRect[1] += AdjHt; // Adjust Top Side

            CurrRect[2] += AdjWid;  // Adjust Right Side

            CurrRect[3] -= AdjHt; // Adjust Bottom Side

            // Apply the new crop area to the crop box of all the pages

            this.setPageBoxes({cBox:"Crop", nStart:0, nEnd:this.numPages-1, rBox:CurrRect});

            var CurrRect = this.getPageBox({cBox:"Crop", nPage:0});

            this.setPageBoxes({cBox:"Bleed", nStart:0, nEnd:this.numPages-1, rBox:CurrRect});

            this.setPageBoxes({cBox:"Trim", nStart:0, nEnd:this.numPages-1, rBox:CurrRect});

            this.setPageBoxes({cBox:"Art", nStart:0, nEnd:this.numPages-1, rBox:CurrRect});

             

            Thanks,

            Ken

            • 3. Re: Get the objects on a page or get the selection with JavaScript?
              KenWK Level 1

              Great gobs of gratitude to MD_quake for posting back here when he/she found his/her answer.

               

              Turns out the boxes WERE changing, but the &#*$%! crop dialog wasn't showing the changes on all the boxes! Saving the file and opening it again shows the boxes correctly. Per MD's post you can also use a preflight.


              I ended up with this JavaScript but might also change the media box to clean things up a bit.

              var TargetWid=302

              var TargetHt=477

              // Get the crop box for the page

              var CurrRect = this.getPageBox({cBox:"Crop", nPage:0});

              var AdjWid = (TargetWid-CurrRect[2])/2

              var AdjHt = (TargetHt-CurrRect[1])/2

              //app.alert(AdjWid);

              // Set the new crop area of the box (in pixels)

              CurrRect[0] -= AdjWid;  // Adjust Left Side

              CurrRect[1] += AdjHt; // Adjust Top Side

              CurrRect[2] += AdjWid;  // Adjust Right Side

              CurrRect[3] -= AdjHt; // Adjust Bottom Side

              // Apply the new crop area to the crop box of all the pages

              this.setPageBoxes({cBox:"Crop", nStart:0, nEnd:this.numPages-1, rBox:CurrRect});

              //Reset the CurrRect to the new crop and set the other boxes

              var CurrRect = this.getPageBox({cBox:"Crop", nPage:0});

              this.setPageBoxes({cBox:"Art", nStart:0, nEnd:this.numPages-1, rBox:CurrRect});

              this.setPageBoxes({cBox:"Trim", nStart:0, nEnd:this.numPages-1, rBox:CurrRect});

              this.setPageBoxes({cBox:"Bleed", nStart:0, nEnd:this.numPages-1, rBox:CurrRect});

               

              Best,
              Ken