Skip to main content
Known Participant
October 24, 2008
Question

How to create a Book in Indesign and add indesign documents to it?

  • October 24, 2008
  • 3 replies
  • 2804 views
Hi all,

Can I create a book in InDesign CS3 and add indesign documents to it using javascript.

Thanks,
Hemachandiran.
This topic has been closed for replies.

3 replies

Inspiring
October 24, 2008
Hi K.

you may look for an object called textFrame in the DOM (e.g. in ESTK) and find out the methods of it. There you might find something called exportFile() and it's parameters.

Martin
Known Participant
October 24, 2008
Its really useful martin.

Thanks.

I have another doubt, can i export the text frame contents to an RTF format using cs3. (using javascript)
Inspiring
October 24, 2008
Hi K.

yes, you can.

Takt a look at this pretty old piece of code:


// bookOfSelectedFolder.jsx
//DESCRIPTION: Create a book and add indd-files of a choosen folder

var myFolder = Folder.selectDialog( "Choose a folder" );
if( myFolder != null ){
// get indd-files of choosen folder
var myFiles=myFolder.getFiles( "*.indd" );
if ( myFiles.length > 0 ){
var myBookFileName = myFolder + "/"+ myFolder.name + ".indb";
myBookFile = new File( myBookFileName );
try{
//does the book file exist?
myBook=app.open( myBookFile );
}
catch ( e ){
//the book file doesn't exist, so make a new one
myBook=app.books.add( myBookFile );
myBook.automaticPagination=false;
for ( i=0; i < myFiles.length; i++ ){
myBook.bookContents.add( myFiles );
}
myBook.save( );
}
}
}


Martin
January 4, 2011

Hi.

This script was fantastic through CS3, but now in CS4, it crashes the application. When I use the debugger in the ESTK, it crashes around this line:

myBook=app.open( myBookFile );

Does anyone know what the difference is in CS3 and 4 that is causing the error? I'm still learning how to script and have not been able to figure it out myself.

Thanks in advance.

Kasyan Servetsky
Legend
January 10, 2011

Here's my version of the script — now works in CS4 — may be it would come in handy to somebody:

var myFolder = Folder.selectDialog( "Select a folder with InDesign files" );
if ( myFolder != null ) {
     var myFiles = [];
     var myAllFilesList = myFolder.getFiles();

     for (var f = 0; f < myAllFilesList.length; f++) {
          var myFile = myAllFilesList;
          if (myFile instanceof File && myFile.name.match(/\.indd$/i)) {
               myFiles.push(myFile);
          }
     }
     
     if ( myFiles.length > 0 ) {
          var myBookFileName = myFolder + "/"+ myFolder.name + ".indb";
          myBookFile = new File( myBookFileName );
          if ( myBookFile.exists ) {
               if ( app.books.item(myFolder.displayName + ".indb") == null ) {
                    myBook = app.open( myBookFile );
               }
          }
          else {
                myBook = app.books.add( myBookFile );
                myBook.automaticPagination = false;
                for ( i=0; i < myFiles.length; i++ ) {
                    myBook.bookContents.add( myFiles );
                }
                myBook.save( );
           }
     }
}