Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Align TextFrame to page margins with JS

New Here ,
Sep 28, 2010 Sep 28, 2010

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 ?

indesign.jpgindesign.jpg

TOPICS
Scripting
2.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advisor , Sep 28, 2010 Sep 28, 2010

Hey!

You can do it like this:

var myPage = app.activeWindow.activePage;
var myMargins = myPage.marginPreferences;
if(app.selection.length){
    app.selection[0].geometricBounds = [myPage.bounds[0]+myMargins.top,myPage.bounds[1]+myMargins.left,myPage.bounds[2]-myMargins.bottom,myPage.bounds[3]-myMargins.right];
}else{
    myPage.textFrames[0].geometricBounds = [myPage.bounds[0]+myMargins.top,myPage.bounds[1]+myMargins.left,myPage.bounds[2]-myMargins.bottom,myPage.bounds[3]-myMargins.right];
}

HTH

--

tomaxxi

...
Translate
Valorous Hero ,
Sep 28, 2010 Sep 28, 2010

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;
     }
     else{
          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];
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 03, 2017 Aug 03, 2017

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

How to do that?

Thank you!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Sep 28, 2010 Sep 28, 2010

Hey!

You can do it like this:

var myPage = app.activeWindow.activePage;
var myMargins = myPage.marginPreferences;
if(app.selection.length){
    app.selection[0].geometricBounds = [myPage.bounds[0]+myMargins.top,myPage.bounds[1]+myMargins.left,myPage.bounds[2]-myMargins.bottom,myPage.bounds[3]-myMargins.right];
}else{
    myPage.textFrames[0].geometricBounds = [myPage.bounds[0]+myMargins.top,myPage.bounds[1]+myMargins.left,myPage.bounds[2]-myMargins.bottom,myPage.bounds[3]-myMargins.right];
}

HTH

--

tomaxxi

http://indisnip.wordpress.com/

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 19, 2024 Nov 19, 2024
LATEST

@abstract_kid6C1A 

How to make an image fit into margin and column width, scaled equally by width

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines