Skip to main content
Inspiring
June 7, 2022
Answered

TOC Creation request

  • June 7, 2022
  • 1 reply
  • 503 views

HI,

I have trouble to enable the "includeBookDocuments" and "removeForcedLineBreak", my code is here, but the resule was enabled "bookmarks" and "replace toc".

 

I need to enable "includeBookDocuments" and "removeForcedLineBreak" only.

 

kindly chec my code and correct me..

 

var tocStyles = ["style1","Style2","Style3"];


var doc = app.activeDocument;
var tocNewStyle = doc.paragraphStyles.add({name:"tempTOC", appliedFont:"Arial", fontStyle: "Regular", pointSize:2});

var myTOC = app.activeDocument.tocStyles.add();
myTOC.name = "MyTOCStyle";
myTOC.title = "Contents";
myTOC.titleStyle = app.activeDocument.paragraphStyles[3]; // enter the paragraph style to apply to the TOC title.
myTOC.includeBookDocuments = true;
myTOC.removeForcedLineBreak = true;

for(i=0; i<tocStyles.length; i++)
{
style = app.activeDocument.paragraphStyles.item(tocStyles[i]); // enter the paragraph style for "include paragraph styles"
myTOC.tocStyleEntries.add({formatStyle:tocNewStyle, name:style.name, separator:"\t"});
}
app.activeDocument.createTOC(myTOC);

 

 

This topic has been closed for replies.
Correct answer Peter Kahrel

You need to tell createTOC() which book and which TOC style to use:

app.activeDocument.createTOC (myTOC, true, myBook);

 

1 reply

Peter Kahrel
Community Expert
Community Expert
June 7, 2022

The options that you highlighted don't work when you generate the TOC with a script. It's a known bug.

P.

$rikanthAuthor
Inspiring
June 7, 2022

Hi Peter,

Is there any way to prodecue the TOC.

 

Peter Kahrel
Community Expert
Peter KahrelCommunity ExpertCorrect answer
Community Expert
June 7, 2022

You need to tell createTOC() which book and which TOC style to use:

app.activeDocument.createTOC (myTOC, true, myBook);