Trainings

Friday, August 1, 2014

InDesign Script: create an Indesign book and add documents to book and finally export book to pdf.

/************************************************
  1. Create an InDesign book
  2. add documents to InDesign book - bookContents object to be used
  3.. export book as a pdf

 **************************************************/


var filein ="/C/prashant/indd/Book3.indb" ; //path for indesign book which needs to be exported as pdf.
var fileout = "/C/prashant/indd/Book2.pdf" ;    //path for the exported pdf
var notesDoc = "/C/prashant/indd/HelloWorld.indd" ;


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

//1. Create / Open a book
//if book does not exists then create it
if(!mybook.exists)
{
    //create a new book
    var book = app.books.add(mybook);  
}
else{
    //book exists so we can open it.    
    var book = app.open(mybook);  //open book
}

//2. add documents to book
book.bookContents.add(File(notesDoc));

//3. export book to pdf
book.exportFile(ExportFormat.PDF_TYPE,mypdf);

//close book without save the book.
book.close(SaveOptions.NO);