12 Replies Latest reply on Nov 2, 2016 2:06 PM by George_Johnson

    Acrobat document resizing

    JKuruvilla

      Hello,

      I want to use an applescript to resize my acrobat document (JavaScript also will do). Note that, this is not crop. My current document size is 7.5 inch x 10 inch and I want to make it 8.5 inch x 11 inch. This function available in crop tool (Set Page Boxes/Change Page size/Custom) if I want to do manually. Any help please?

        • 1. Re: Acrobat document resizing
          George_Johnson MVP & Adobe Community Professional

          With JavaScript you'd use the setPagesBoxes method to first set the media box to the size you want and then set the crop box to match.

          • 2. Re: Acrobat document resizing
            JKuruvilla Level 1

            Can you please give me little more insight on this?

            • 3. Re: Acrobat document resizing
              George_Johnson MVP & Adobe Community Professional

              Exactly how do you want to go from 7.5 x 10 to 8.5 x 11? It might be by adding an inch to the right side, or 1/2 inch to both the left and right sides. Same thing for the top and bottom.

               

              Also, do you want to do this for every page in the document, or just certain ones?

              • 4. Re: Acrobat document resizing
                JKuruvilla Level 1

                Thanks George for your feed back. I know how to do this manually, I have a bunch of PDFs with single pages. I am trying to find out an automated system such as applescript or JavaScript for the ongoing solution.

                • 5. Re: Acrobat document resizing
                  George_Johnson MVP & Adobe Community Professional

                  Yes, I'm willing to show you how, but it would be helpful if you provided the information I asked about. The details are important.

                  • 6. Re: Acrobat document resizing
                    JKuruvilla Level 1

                    Yes. It is single page document. I want to add 1/2 inch each on all four sides. meaning currently, it is 7.5x10 inches and want to get it as 8.5x11. thanks again.

                    • 7. Re: Acrobat document resizing
                      George_Johnson MVP & Adobe Community Professional

                      Here's a basic script that should help you get started. It adds 1/2 inch to all sides of the page and assumes the page isn't rotated.

                       

                      // Get the rect (left, top, right, bottom) for the media box of the current page

                      var aRect = getPageBox({cBox: "Media", nPage: 0});

                       

                      // Set the  increment value, in points (72 points/inch)

                      var inc = 0.5 * 72;

                       

                      // Set a new media box

                      setPageBoxes({cBox: "Media", nStart: 0, nEnd: numPages - 1, rBox: [aRect[0] - inc, aRect[1] + inc, aRect[2] + inc, aRect[3] - inc]});

                       

                       

                      You can run this script in the interactive JavaScript console (command + J), in a custom action, custom toolbar or menu item, etc. Post again if you need more help and consulting the Acrobat JavaScript reference is always a good idea.

                      • 8. Re: Acrobat document resizing
                        Dima_Tysha

                          pageCnt = this.numPages;

                          // calc target dim in pt

                          var targetPageWidth = nSiX * 72 / 25.4;

                          var targetPageHeight = nSiY * 72 / 25.4;

                         

                          t.duration = pageCnt;

                          t.begin();

                         

                          for (var i = 0; i < pageCnt; i++ ){

                         

                         

                          t.value = i;

                          t.text = "Зміна розміру сторінки " + (i + 1);

                          // для MediaBox

                          var oRect = this.getPageBox("Media", i);// get old value of MediaBox

                          // розрахувати різницю

                          var mediaBox_dX = (targetPageWidth - oRect[2] - oRect[0]) / 2;

                          var mediaBox_dY = (targetPageHeight - oRect[1] - oRect[3]) /2;

                          // set new dimentions

                          this.setPageBoxes({

                          cBox: "Media",

                          nStart: i,

                          rBox:[

                          oRect[0] - mediaBox_dX,

                          oRect[1] + mediaBox_dY,

                          oRect[2] + mediaBox_dX,

                          oRect[3] - mediaBox_dY,

                          ]

                          });

                          // для CropBox

                          var oRect = this.getPageBox("Crop", i);// get old value of CropBox

                         

                         

                          var dX = (targetPageWidth - oRect[2] - oRect[0]) / 2;

                          var dY = (targetPageHeight - oRect[1] - oRect[3]) /2;

                          // set new dimentions

                          this.setPageBoxes({

                          cBox: "Crop",

                          nStart: i,

                          rBox:[

                          oRect[0] - dX,

                          oRect[1] + dY,

                          oRect[2] + dX,

                          oRect[3] - dY,

                          ]

                          });

                         

                         

                          // для TrimBox

                          var oRect = this.getPageBox("Trim", i);// get old value of TrimBox

                          this.setPageBoxes({

                          cBox: "Trim",

                          nStart: i,

                          rBox:[

                          oRect[0] + mediaBox_dX,

                          oRect[1] + mediaBox_dY,

                          oRect[2] + mediaBox_dX,

                          oRect[3] + mediaBox_dY,

                          ]

                          });

                         

                          // для BleedBox

                          var oRect = this.getPageBox("Bleed", i);// get old value of BleedBox

                          this.setPageBoxes({

                          cBox: "Bleed",

                          nStart: i,

                          rBox:[

                          oRect[0] + mediaBox_dX,

                          oRect[1] + mediaBox_dY,

                          oRect[2] + mediaBox_dX,

                          oRect[3] + mediaBox_dY,

                          ]

                          });

                          // для ArtBox

                          var oRect = this.getPageBox("Art", i);// get old value of ArtBox

                          this.setPageBoxes({

                          cBox: "Art",

                          nStart: i,

                          rBox:[

                          oRect[0] + mediaBox_dX,

                          oRect[1] + mediaBox_dY,

                          oRect[2] + mediaBox_dX,

                          oRect[3] + mediaBox_dY,

                          ]

                          });

                          }

                          t.end();

                        • 9. Re: Acrobat document resizing
                          JKuruvilla Level 1

                          Thanks George, I think I am very close. I am getting the following error.

                          ReferenceError: aRect is not defined

                          1:Console:Exec

                          undefined

                          • 10. Re: Acrobat document resizing
                            George_Johnson MVP & Adobe Community Professional

                            When you execute it in the console, you have to select all of it and press command+return.

                            • 11. Re: Acrobat document resizing
                              JKuruvilla Level 1

                              Thanks George. This works Good. One more question. How can I put this in loop? so that, I can select a bunch of PDFs, run at one time. Probably, an external script? how that will work?

                              • 12. Re: Acrobat document resizing
                                George_Johnson MVP & Adobe Community Professional

                                That what custom Actions are for. You can set one up with a single JavaScript action and process the files you select when you trigger the action. You should be able to find more information on creating and using Action in Acrobat with a search.