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

Resize two text frames

Community Beginner ,
May 06, 2011 May 06, 2011

I have two text frames on a page. When the top one is overset, I want it to resize the height so all the content is visible meanwhile reducing the height of the second text frame on the same page. If the top one is not overset and the textframe height is larger than the content, I want to resize it so the second text frame increases in size etc.

How do I accomplish this using a script? (cannot use plugins, must be a script)

TOPICS
Scripting
1.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
Guest
May 09, 2011 May 09, 2011

You can do it like this with javascript:

function resizeTwoTextFrames(myPage, spaceBetweenTextFrames){ // resizes the top two textframes of a page
     if (myPage.textFrames.length>2){
          alert("Page must contain at least two textframes");
          return;
     }
     var myTextFrames = myPage.textFrames.everyItem().getElements().sort(function(a,b){return a.geometricBounds[0]>b.geometricBounds[1]}); // sorts every textframe on the page by the top margin
     var topTextFrame = myTextFrames[0];
     var lowerTextFrame = myTextFrames[1];
     topTextFrame.fit(FitOptions.FRAME_TO_CONTENT);
     lowerTextFrame.geometricBounds = [topTextFrame.geometricBounds[2]+spaceBetweenTextFrames,lowerTextFrame.geometricBounds[1],lowerTextFrame.geometricBounds[2],lowerTextFrame.geometricBounds[3]]
}

resizeTwoTextFrames(app.activeWindow.activePage, 0);


You might want to change the method of selecting the two textframes in question. This will take the top two textframes on the page.

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
LEGEND ,
May 09, 2011 May 09, 2011

Typo?

sort(function(a,b){return a.geometricBounds[0]>b.geometricBounds[1]})
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
Guest
May 09, 2011 May 09, 2011

John Hawkinson wrote:

Typo?

sort(function(a,b){return a.geometricBounds[0]>b.geometricBounds[1]})

Yes, it's a typo. This is what it's supposed to be:

sort(function(a,b){return a.geometricBounds[0]>b.geometricBounds[0]})

Here's the whole script with the typo corrected

function resizeTwoTextFrames(myPage, spaceBetweenTextFrames){ // resizes the top two textframes of a page
     if (myPage.textFrames.length>2){
          alert("Page must contain at least two textframes");
          return;
     }
     var myTextFrames = myPage.textFrames.everyItem().getElements().sort(function(a,b){return a.geometricBounds[0]>b.geometricBounds[0]}); // sorts every textframe on the page by the top margin
     var topTextFrame = myTextFrames[0];
     var lowerTextFrame = myTextFrames[1];
     topTextFrame.fit(FitOptions.FRAME_TO_CONTENT);
     lowerTextFrame.geometricBounds = [topTextFrame.geometricBounds[2]+spaceBetweenTextFrames,lowerTextFrame.geometricBounds[1],lowerTextFrame.geometricBounds[2],lowerTextFrame.geometricBounds[3]]
}

resizeTwoTextFrames(app.activeWindow.activePage, 0);

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
Community Expert ,
May 10, 2011 May 10, 2011

Another typo?

length>2

Should be

length<2

in the if-statement…

Uwe

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
Guest
May 11, 2011 May 11, 2011

Very good! That was not a typo, it was a test to see if you were paying attention.

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
Community Beginner ,
May 18, 2011 May 18, 2011

Thanks for the reply. However this is what I want:

When there's two text frames on a page one after the other, I want to delete the first textframe and resize the other textframe so it takes up the whole page. How do I do this with a script? I tried modifying the geometric bounds (secondTextFrame.GeometricBounds[0] = 0 but it doesn't move up)

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
LEGEND ,
May 18, 2011 May 18, 2011

secondTextFrame.GeometricBounds[0] = 0

This construction fetches secondTextFrame.geometricBounds (an array), keeps it hanging out there, and changes the value of the first element, and then throws the array away. You must use a temporary variable:

var b = secondTextFrame.geometricBounds;

b[0] = 0;

secondTextFrame.geometricBounds = b;

(well, ok, I guess you could do it on one line without the temp. var)

That said, it seems like you should use the bounds of the current page, or something, just in case somebody moves the zero point.

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
Community Beginner ,
May 18, 2011 May 18, 2011

Thanks, how do I set it to the geometric bounds of the page margin? I tried textFrame.GeometricBounds =  page.Bounds but that set it above the visible area etc.

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
LEGEND ,
May 18, 2011 May 18, 2011

"visible area"? What does that mean?

What do you want?

Are you saying you would like to stay within the page margins?

Please be specific in your questions.

If you want the margin, you'll have to adjust the bounds array

yourself based on the values of the margins which you can look

up in the Page's marginPreferences.

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
Community Beginner ,
May 18, 2011 May 18, 2011

TextFrame  secondTextFrame;

var a = secondTextFrame.GeometricBounds;

Page someRandomPage= doc.Pages[4];

var b = someRandomPage.GeometricBounds;

a = b;

secondTextFrame.GeometricBounds = a;

The above code fixes the problem BUT depending on the document, there may not be a page 4 (there maybe only 2 pages etc). Instead of getting the geometric bounds from a random page, how do I get it from the page margins?

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
LEGEND ,
May 18, 2011 May 18, 2011
LATEST

Why would you use page 4? I just don't understand what's going on here.

If you want to pick a random page, you could pick page zero.

But a better choice is probably to use the page the textFrame is actually on.

You know, b = secondTextFrame.parentPage.bounds;

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