Skip to main content
Participating Frequently
October 24, 2008
Question

how to add pages and extend textarea to fit imported text

  • October 24, 2008
  • 4 replies
  • 577 views
I would like to create a script that will add a page to my (new) document, and automatically continue the textarea from my first page to the new page.

I am new to InDesign scripting, and not sure how to best approach this.

If I have:

myPage //the first and only page on my new document
myTextArea //the first and only textarea on page myPage

what technique could I use? what properties or methods?

Thank you!
This topic has been closed for replies.

4 replies

Participating Frequently
October 24, 2008
Thanks again - I was confusing my variable name with the object. I came across your blog and find it as helpful as these forums - seems like a very helpful community so far.
Inspiring
October 24, 2008
One thing you're going to need to do to script successfully is call things by their right names. There is no such animal as a textArea, although it's ok to call a TextFrame that (or any other legal name).

If a story threads through several pages, then each page has a text frame. You can get an array of them by using:

myStory.textContainers

where "myStory" is a reference to the story in question.

Dave
Participating Frequently
October 24, 2008
Thanks much.

One more question if anyone can address: If I used a textarea.fit after importing text, and it automatically adds and occupies multiple pages, is it technically a single textarea, that I can still reference with the myTextArea variable assigned when it was only on the first page? Or, is it multiple text areas?
Inspiring
October 24, 2008
1. add a page to your document:

var myNewPage = myDoc.pages.add(); // adds to end of document

2. add a text frame to the page that fits its margins

var myNewTF = myNewPage.textFrames.add({geometricBounds:getLiveBounds(myNewPage)});

for this to execute, you need this function in your script:
function getLiveBounds(page) {

var bounds = page.bounds;
return [
page.marginPreferences.top,
page.side == PageSideOptions.leftHand ?
bounds[1] + page.marginPreferences.right :
bounds[1] + page.marginPreferences.left,
bounds[2] - page.marginPreferences.bottom,
page.side == PageSideOptions.leftHand ?
bounds[3] - page.marginPreferences.left :
bounds[3] - page.marginPreferences.right
]
}


3. Thread that new frame to your existing frame:

myNewTF.previousTextFrame = myTextArea;

That's it.

Dave
Harbs.
Legend
October 25, 2008
Hi Dave,
> myNewTF.previousTextFrame = myTextArea;
>
I think it's better practice to use:

myTextArea.nextTextFrame = myNewTF;

IIRC, the first approach causes the first text frame's story to be appended to the second one's. This effectively removes the original story and creates a new one (with the default story properties). This can cause weird problems if the default properties are different than the existing story's properties...

--
Harbs
http://www.in-tools.com