Thursday, July 31, 2014

InDesign Script : Update Table of content ( TOC )

To update Table of content / TOC using InDesign Script , Code is given below highlighted in Pink.

Note : 
1. This article assumes that you have already create TOCStyle and Table of content
and you want to update TOC at run time by indesign script.

2. TOCStyle is already created in document "TOCDocument.indd"
3. while exporting document , to include Table of Content as a bookmarks in pdf , use exportPdf seetings to export table of content as bookmarks. Otherwise TOC will not appear in PDF.

 //path for indesign book which needs to be exported as pdf.
var filein ="/C/prashant/indd/TOCDocument.indd" ;

var fileout = "/C/prashant/indd/TOCDocument.pdf" ;    //path for the exported pdf
var TOCStyle = "TOCStyle"; //this name can be changed depend on the TOCStyle.

var mypdf = new File(fileout);  //create pdf file object

//Open InDesign book
var doc =;  //open book

var tocStyles = doc.tocStyles ; //get all tocs from a document
var TOCStyle = tocStyles.itemByName(TOCStyle);  //got the fundbridge TOC style.
doc.createTOC(TOCStyle,true); // to update TOC pass replacing = true i.e. second argument of creatTOC() method.

//export book to pdf

//close book