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

Generate TOC with JavaScript

Explorer ,
Oct 10, 2013 Oct 10, 2013

I have a JavaScript script that opens an InDesign template and inserts text (including placing RTF files) on various pages throughout the template. Page 2 is empty, and I want to automatically generate a table of contents and place it on that page. When I use the following command, it always places it on page 1:

doc.createTOC(doc.tocStyles.item("TOC"), true, null, ["1.0i", "1.0i"]);

How do I get it on page 2? Thanks!

TOPICS
Scripting
1.2K
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
Mentor ,
Oct 11, 2013 Oct 11, 2013

Hi,

Move its text container (this is array of stories):

//...

var

     doc = app.activeDocument,

     mTOC = doc.createTOC(doc.tocStyles.item("TOC"), true, null, ["1.0i", "1.0i"])[0].textContainers[0];

mTOC.move(doc.pages[1]);

mTOC.move(["1.0i", "1.0i"]);

//...

Jarek

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
Explorer ,
Oct 11, 2013 Oct 11, 2013

Jarek,

Thank you for the helpful suggestion, which I tried. It works, but I have two questions:

1. I already have a text frame on page 2 that is set up for automatic reflow. If my TOC takes more than one page, how do I deal with that with the move technique? I would prefer to grab the story contents from the TOC and put them in the text frame on page 2. Is this possible?

2. The main body of the document ends up with 28 pages of connected text. When I omit the createTOC step, the document flows properly and I have no overset text. When I include the createTOC (whether I leave it on page 1 or move it to page 2), the automatic reflow stops about three pages before the end of the document and gives me an overset text error. The only code difference in these two scenarios is whether or not I comment out the createTOC statement. Any idea why it messes with the automatic reflow of the body text?

Dan

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
Mentor ,
Oct 11, 2013 Oct 11, 2013
LATEST

Hi,

1. I already have a text frame on page 2...

While creating TOC its textFrame is marked so TOC story could be updated easy. If you move a story - not a text Frame - this connection is broken.

None the less you can use a move method to a story as well. (see http://jongware.mit.edu/idcs5js/pc_Story.html#move)

2 ... the automatic reflow stops about three pages before the end of the document and gives me an overset text error....

Hard to say anything with no look at the code...

Jarek

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