2 Replies Latest reply on Aug 3, 2014 5:00 PM by sighmoan

    Adjust margins to an equation based on document size

    sighmoan Level 1

      Apologetically I'm a newbie to InDesign scripting but I've been doing my reading trying to understand the Javascript route since it's the one I'm most familiar with.

       

      So my problem is trying to understand how to set up a new document (or adjust an existing document) to set the page margins to a mathematical equation:

       

      I would want the same margin all around set to Page Height + Page Width / 40. I've been able to set the page margins via scripts but am at a loss when it comes to expressing the variables.

       

      Please help! Thanks. Simon

        • 1. Re: Adjust margins to an equation based on document size
          Jump_Over Level 5

          Hi,

           

          Setting a margins directly to some value or to variable is the same. Exam this:

          var
            mH = "180 mm",
            mW = "250 mm",
            mDoc = app.activeDocument,
            mMargin = ( parseInt(mH) + parseInt(mW) ) / 40  + " mm";
          
          with (mDoc.documentPreferences) {
            pageHeight = mH;
            pageWidth = mW;
            }
          
          with (mDoc.pages[0].marginPreferences) {
            top = mMargin;
            right = mMargin;
            bottom = mMargin;
            left = mMargin;
            }
          

           

          The problem could be if document exists already. In this case setting document.marginPreferences doesn't effect for pages inside a doc.

          (since each page is created already and can have its own margins)

          You have to set specific page.marginPreferences (or applied master page).

           

          Jarek

          • 2. Re: Adjust margins to an equation based on document size
            sighmoan Level 1

            Thanks Jarek, that's certainly helped to wrap my head around the treatment of the variables. Now for the fun part of trying to work this as a UI when creating a new document!

             

            I definitely understand about the problem with an already existing document as the marginPreferences only deal with single pages. Setting this up to create a new document from the get-go is the way to go!

             

            S