8 Replies Latest reply on Aug 27, 2012 7:03 AM by Trevorׅ

    Multiple page sizes

    tim.j.c

      I would like to resize all the pages of a document according to the width/height values stored  in 2 text boxes,  this info comes from a database using Data merge to import it.

      I need to resize the pages using millimeters but my 1st attempt will only resize all pages using Points

      and the 2nd is incorrect because the Object does not support the pageWidth method.

       

      1)

      var myDocument = app.activeDocument;

          var myPages = myDocument.pages;

       

             for(var myCounter = 0; myCounter < myPages.length; myCounter ++){

         var WidthTextFrame = myPages.item(myCounter).textFrames.item(7);

         var WidthVal = parseInt(WidthTextFrame.contents);

         var HeightTextFrame= myPages.item(myCounter).textFrames.item(6);

         var HeightVal = parseInt(HeightTextFrame.contents);

       

         myPages.item(myCounter).resize(CoordinateSpaces.INNER_COORDINATES, AnchorPoint.CENTER_ANCHOR, ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,[WidthVal , HeightVal]);               

                }

       

      2)

         var myDocument = app.activeDocument;

          var myPages = myDocument.pages;

       

             for(var myCounter = 0; myCounter < myPages.length; myCounter ++){

         var WidthTextFrame = myPages.item(myCounter).textFrames.item(7);

         var WidthVal = parseInt(WidthTextFrame.contents);

         var HeightTextFrame= myPages.item(myCounter).textFrames.item(6);

         var HeightVal = parseInt(HeightTextFrame.contents);

       

             myPages.item(myCounter).pageWidth = WidthVal + "mm";

             myPages.item(myCounter).pageHeight = HeightVal + "mm";

                 }

       

      I would greatly appreciate it if anyone could correct either method to make all pages resize using millimeters.

       

      Many Thanks

      Tim

        • 1. Re: Multiple page sizes
          [Jongware] Most Valuable Participant

          tim.j.c wrote:

           

          .. I need to resize the pages using millimeters but my 1st attempt will only resize all pages using Points

           

          So this document is set up with Points as its default measurement units. Change it to millimeters before running the rest of your script:

          http://jongware.mit.edu/idcsjs5.5/pc_ViewPreference.html#horizontalMeasurementUnits (and verticalMeasurementUnits on that same page)

           

          Be kind to your users: before changing the units, store the original settings and restore them after you are done.

          • 2. Re: Multiple page sizes
            Laubender Adobe Community Professional & MVP

            @Jongware – resize() takes only points as measurement.

             

            @Tim – for identifying the text frame for "width" and "height" I'd take another approach:

            1. rename the frames according to their meaning in the layers palette like "width" and "height" before data merge

            2. to feed resize() the right width and height values in points transform the mm values provided by the text frame's contents to points with the factor 2.835:

             

            var myDocument = app.activeDocument;
            var myPages = myDocument.pages;
            
            var factor = 2.835; //point = mm * factor
            var WidthVal;
            var HeightVal;
            
            for(var p = 0; p < myPages.length; p++){
            
                var pageItemsOfPage = myPages[p].pageItems.everyItem().getElements();
            
                for(var n=0;n<pageItemsOfPage.length;n++){
            
                    //If my page item is a text frame AND its name is "width", then extract its contents and multiply with our factor:
                    if(pageItemsOfPage[n] instanceof TextFrame && pageItemsOfPage[n].name == "width"){
                        WidthVal = parseInt(pageItemsOfPage[n].contents) * factor;
                        break;
                        };
                    };
            
            
                for(var n=0;n<pageItemsOfPage.length;n++){
            
                    //If my page item is a text frame AND its name is "height", then extract its contents and multiply with our factor:
                    if(pageItemsOfPage[n] instanceof TextFrame && pageItemsOfPage[n].name == "height"){
                        HeightVal = parseInt(pageItemsOfPage[n].contents) * factor;
                        break;
                        };
                    };
            
               myPages[p].resize(CoordinateSpaces.INNER_COORDINATES, AnchorPoint.CENTER_ANCHOR, ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,[WidthVal , HeightVal]);               
            
                };
            

             

            Uwe

            • 3. Re: Multiple page sizes
              [Jongware] Most Valuable Participant

              It *defaults* to points, much to my surprise I admit. But what about the final optional parameter "consideringRulerUnits", then?

               

              (http://jongware.mit.edu/idcsjs5.5/pc_Rectangle.html#resize)

              • 4. Re: Multiple page sizes
                [Jongware] Most Valuable Participant

                Oh wait:

                 

                "This parameter has no effect unless the reference point is specified relative to a page."

                 

                So it *ignores* your current measurement units, then? How odd.

                • 5. Re: Multiple page sizes
                  Laubender Adobe Community Professional & MVP

                  @Jongware – how would you "specify the reference point relative to a page" other than "CoordinateSpaces.INNER_COORDINATES" when you want to " resize()" a page?

                   

                  In the snippet I offered that is obviously not true in the sence of the documentation or I do not fully understand it. I tried both parameters, "false" (default) and "true". No difference…

                   

                  myPages[p].resize(
                  
                       CoordinateSpaces.INNER_COORDINATES,
                       AnchorPoint.CENTER_ANCHOR,
                       ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,
                       [WidthVal, HeightVal],
                       true,
                       true //false = default
                  
                       );
                  

                   

                  Uwe

                  • 6. Re: Multiple page sizes
                    bobhopfner

                    I am doing something similar but I am getting objects that shift slightly out of place. These object highlight text but when I scale them all, they are not behind the text as they should be. I should figure out a GREP style to hightlight them with a modify underline - but I digress . . .

                     

                    Also I can't enlarge a page. I seem to need to be able to adjust the slug area to allow be to scale up a page to 300%. Then things won't fall off the pasteboard and cause errors.

                     

                    thanks,

                    Bob

                    • 7. Re: Multiple page sizes
                      Sivaraman Murugan

                      Hi,

                       

                      I have the same issue, resize should be based on mm instead of points. Could anyone please help me?

                       

                       

                       

                      thanks,

                      Siva

                      • 8. Re: Multiple page sizes
                        Trevorׅ Adobe Community Professional

                        [Jongware] wrote:

                         

                        "This parameter has no effect unless the reference point is specified relative to a page."

                         

                         

                        Did anybody figure this out yet?