3 Replies Latest reply on Aug 3, 2017 6:30 AM by Ribnog

    Align TextFrame to page margins with JS


      If i have the above page and a textframe in the center what is the javascript code to align / fit the textframe to the page margins ?



        • 1. Re: Align TextFrame to page margins with JS
          Kasyan Servetsky Level 5

          var doc = app.activeDocument;
          var page = doc.pages[0];
          var textFrame = page.textFrames[0];
          textFrame.geometricBounds = myGetBounds(doc, page);

          function myGetBounds(myDocument, myPage){
               var myPageWidth = myDocument.documentPreferences.pageWidth;
               var myPageHeight = myDocument.documentPreferences.pageHeight
               if(myPage.side == PageSideOptions.leftHand){
                    var myX2 = myPage.marginPreferences.left;
                    var myX1 = myPage.marginPreferences.right;
                    var myX1 = myPage.marginPreferences.left;
                    var myX2 = myPage.marginPreferences.right;
               var myY1 = myPage.marginPreferences.top;
               var myX2 = myPageWidth - myX2;
               var myY2 = myPageHeight - myPage.marginPreferences.bottom;
               return [myY1, myX1, myY2, myX2];

          1 person found this helpful
          • 2. Re: Align TextFrame to page margins with JS
            Marijan Tompa [tomaxxi] Level 4



            You can do it like this:


            var myPage = app.activeWindow.activePage;
            var myMargins = myPage.marginPreferences;
                app.selection[0].geometricBounds = [myPage.bounds[0]+myMargins.top,myPage.bounds[1]+myMargins.left,myPage.bounds[2]-myMargins.bottom,myPage.bounds[3]-myMargins.right];
                myPage.textFrames[0].geometricBounds = [myPage.bounds[0]+myMargins.top,myPage.bounds[1]+myMargins.left,myPage.bounds[2]-myMargins.bottom,myPage.bounds[3]-myMargins.right];







            • 3. Re: Align TextFrame to page margins with JS

              Hi I know this is from 2010! But I need to apply your code to every pages.


              How to do that?


              Thank you!