0 Replies Latest reply on Jun 29, 2015 11:23 AM by Math Kay

    Page Width Adjustment in master pages

    Math Kay Level 1

      Hi scripters,

       

      This script is for Adjusting page width. That is, Adjusting Outside Margin Only. When we run this script, it is making modifications in document page only.  I want changes in master pages and Text should be flowed or extra pages should be deleted automatically according to the page width adjustment. Kindly Please help me on this.

       

      var mySizeStrList= ["0 pt", "3 pt", "6 pt", "9 pt", "12 pt"];
      var mySizeList = [0.0, 3.0, 6.0, 9.0, 12.0];
      try {
         var docRef = app.documents.item(0);
         var outsideMarginChange = dialogWMeasure ("Adjusting Page Margins");
         var insideMarginChange = 0.0;
         //define page to change here
         var pageRef = docRef.pages.item(0);
         changePagemargins (pageRef, outsideMarginChange)
      } catch (e) {
         alert (e);
      }
      
      
      function dialogWMeasure (dlgName) {
         var origLevel = app.scriptPreferences.userInteractionLevel;
          app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
          var myDialog = app.dialogs.add({name:dlgName,  canCancel:true});  
          with(myDialog){   
          with(dialogColumns.add()){ 
           with(borderPanels.add()){  
              with(dialogColumns.add()){   
                  staticTexts.add({staticLabel: "Text width change by:"});  
                  var myRadioButtonGroup=radiobuttonGroups.add();  
                  with(myRadioButtonGroup){  
                      var changeSizePositive=radiobuttonControls.add({staticLabel:"Increase Size", checkedState:true});  
                      var changeSizeNegative=radiobuttonControls.add({staticLabel:"Decrease Size"});  
                  }  
               }   
               with(dialogColumns.add()){  
                  var pageWidField=dropdowns.add({stringList:mySizeStrList, selectedIndex:0});
               }
            }  
          } 
      }
      var userCancelled = true;
      if (myDialog.show() == true ){
          userCancelled = false;
          var myButtonChoice = myRadioButtonGroup.selectedButton;
          var myPagewidthChange = mySizeList[pageWidField.selectedIndex];
          if (myButtonChoice == 1) {
              myPagewidthChange = (myPagewidthChange * -1.0)
           }
       } 
       app.scriptPreferences.userInteractionLevel = origLevel;
       myDialog.destroy();
       if (userCancelled) {  
           throw ("User cancelled");
      } else {
          return  myPagewidthChange;
      }
      }
      
      /*Right margin is outside margin if facing pages*/
      function changePagemargins (pageRef, outsideMarginChange) {
             var myRightMargin = pageRef.marginPreferences.right;
             var myOutsideMargin = myRightMargin + outsideMarginChange;
              var myInsideMargin = pageRef.marginPreferences.left;
             pageRef.marginPreferences.right = myOutsideMargin;
      //to change text frame; assumes text frame fits to margins
            var pageWid = pageRef.bounds[3] - pageRef.bounds[1];
             var pageHgt = pageRef.bounds[2] - pageRef.bounds[0];
             var textFrameRef = pageRef.textFrames.item(0);
             var topMargin = pageRef.marginPreferences.top;
             var botMargin = pageRef.marginPreferences.bottom;
             var gWidth;
             var gHgt = (pageHgt - botMargin);
             if (pageRef.side == PageSideOptions.LEFT_HAND) {
             gWidth = (pageWid - myInsideMargin);
            textFrameRef.geometricBounds = [topMargin, myOutsideMargin, gHgt, gWidth];
            var test = [topMargin, myOutsideMargin, gHgt, gWidth];
             } else {
              gWidth = (pageWid - myOutsideMargin);
             textFrameRef.geometricBounds = [topMargin, myInsideMargin, gHgt, gWidth];
             }
      }