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

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

Community Beginner ,
Oct 24, 2008 Oct 24, 2008
Hi all,

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

Thanks,
Hemachandiran.
TOPICS
Scripting
2.8K
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
Contributor ,
Oct 24, 2008 Oct 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
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
Guest
Jan 03, 2011 Jan 03, 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.

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
Valorous Hero ,
Jan 10, 2011 Jan 10, 2011
LATEST

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( );
           }
     }
}

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
Community Beginner ,
Oct 24, 2008 Oct 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)
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
Contributor ,
Oct 24, 2008 Oct 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
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