Book to Document Script for InDesign CS3
The beauty of (java) scripts is that you don’t need to be able to write them or even fully understand their inner workings in order to benefit. Just as you don’t need to be a mechanic to drive to the store you also don’t need to be a programmer to run a script. Scripts are useful and time saving and you shouldn’t let your unfamiliarity with them keep you from utilizing them.
For this example we’ll implement a script written by Ole at Adobe. This script will turn a book into a single document which can be very time saving in light of the InDesign CS3 book indexing bug.
Steps:
- Open Adobe ExtendScript Toolkit 2
- Copy and paste the script below into the open window
//BookToDocument.jsx //An InDesign CS3 JavaScript // //Moves pages from all documents in a book to a //single, new document. main(); function main(){ if(app.books.length > 0){ if(app.books.item(0).bookContents.length > 0){ myMovePages(app.books.item(0)); } } } function myMovePages(myBook){ var myDocument, myPageCounter, myPage, mySection; var myFileName = File.saveDialog("Save the merged book as:", "*.indd"); //Suppress missing font/file warnings. app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT; var myTargetDocument = app.open(myBook.bookContents.item(0).fullName); var myName = myTargetDocument.name; //Turn user interaction back on again. app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL; //Document.save (to: File , stationery:boolean, versionComments:string, forceSave:boolean):Document myTargetDocument = myTargetDocument.save(File(myFileName)); //Iterate through each document in the book. var myMaximumValue = myBook.bookContents.length; var myProgressBarWidth = 300; var myIncrement = myProgressBarWidth/myMaximumValue; var myProgressPanel = myCreateProgressPanel(myProgressBarWidth); myProgressPanel.show(); myProgressPanel.myProgressBar.value = myIncrement; myProgressPanel.myChapterName.enabled = false; myProgressPanel.myChapterName.text = "Now processing: " + myName; for(var myCounter = 1; myCounter<myBook.bookContents.length; myCounter++){ //Open the book document, suppressing missing font/file warnings. app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT; myDocument = app.open(myBook.bookContents.item(myCounter).fullName); app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL; myProgressPanel.myChapterName.text = "Now processing: " + myDocument.name; for(myPageCounter = 0; myPageCounter<myDocument.pages.length; myPageCounter++){ //Duplicate the page to the merged document. myPage = myDocument.pages.item(myPageCounter).duplicate(LocationOptions.after, myTargetDocument.pages.item(-1)); if(myPageCounter == 0){ //Create the section and copy section properties from the document. myProperties = myDocument.sections.item(0).properties; mySection = myTargetDocument.sections.add(undefined, {pageStart:myTargetDocument.pages.item(-1)}); mySection.properties = myProperties; } } //Close the document without saving. myDocument.close(SaveOptions.NO); myProgressPanel.myProgressBar.value = myIncrement * (myCounter+1); } myProgressPanel.myProgressBar.value = 0; myProgressPanel.hide(); alert("Done!"); function myCreateProgressPanel(myProgressBarWidth){ myProgressPanel = new Window('window', 'Progress'); with(myProgressPanel){ myProgressPanel.myChapterName = add('edittext', [12, 12, myProgressBarWidth, 36], ""); myProgressPanel.myProgressBar = add('progressbar', [12, 12, myProgressBarWidth, 24], 0, myProgressBarWidth); } return myProgressPanel; } } - Windows: File > Save As. Save the file to C:\Program Files\Adobe\Adobe InDesign CS3\Scripts\Scripts Panel\
Mac: HD > Applications > Adobe InDesign CS3 > Scripts > Scripts Panel
Make sure you save it as a JavaScript (*.jsx) file. In this example I saved the script as BooktoDocument.jsx
- In InDesign go to Window > Automation and click on Scripts
This opens up the Script Panel - In the Script Panel you should find your newly saved script under ‘Application’. You can run the script by double clicking on it.
Since this script deals with books you will want your book open before double clicking on the script (BooktoDocument.jsx) - Save the document with a .Indd file extension so you can easily find it later

- Click ‘OK’
- Your merged document will now be in the saved location





September 13th, 2007 at 8:46 pm
[…] your InDesign CS3 book into a single document by using the InDesign CS3 book to document script. Keep in mind you can still keep your book, this merged document is only needed for indexing […]
September 19th, 2007 at 8:15 am
if(app.books.length > 0){
I ran the script and got an error.
maybe should be app.books.length > 0
Check the script above is it correct?
September 19th, 2007 at 5:35 pm
Adam,
The script ran fine for me. What error did you get?
September 21st, 2007 at 2:55 pm
It might help to give the script save location for Macs as well as PCs. I figured it out, but some Mac users may be thrown for a loop by that primitive Windows path beginning with C:
Also I think item 6:
“Save the Script with a .Indd file extension so you can easily find it later”
Should be:
“Save the document created by the script with a .Indd file extension so you can easily find it later.”
September 27th, 2007 at 9:30 pm
I also got an error running the script.
It says:
——————
JavaScript Error!
Error Number: 25
Error String: Expected: )
Line: 15
Source: if(app.books.length > 0)}
Offending Text: ;
——————-
The book has 23 documents
Seems to be the same error as Adam.
Any ideas what could be wrong?
Thanks for helping!
L.
September 28th, 2007 at 3:44 am
Hey Adam and Luc,
We’re going to look into this problem. Something may have gone wonky when we posted the script, we’ll take a look and let you know as soon as we can.
September 29th, 2007 at 12:45 am
NOTICE: The post has been updated to fix the script. There was a missing // on the first line (to comment it) which was probably what was causing the error you all were having.
Copying and Pasting the entire script above should have no problems now.
October 2nd, 2007 at 5:37 pm
I have tried running the script today (10-2-07) and got the same error #25 as Luc got. Except my Source line says: if(app.books.length > 0){
The offending text:;
I have 24 files in my Book list. I tried removing some to see if it worked but it did not.
October 2nd, 2007 at 5:43 pm
There is one more thing I forgot to mention and since I really don’t know much about scripts I am not sure if it’s important. But when I pasted the script into the ExtedScript Toolkit it added a space after each line. Does this matter? And if so, how do you stop it from doing it?
October 2nd, 2007 at 7:14 pm
The spaces shouldn’t matter, but where are you trying to paste it exactly? You should just be pasting it in a simple text editor program and saving it out as a .jsx file. If you are using something like TextEdit on the mac, make sure it really isn’t saving it as an .rtf file as is it’s default.
October 2nd, 2007 at 8:59 pm
I am working with Windows OS and am following the instructions on this website. I opened the ExtendScript Toolkit 2, and pasted the script that I copied from this site, into the toolkit’s window pane. It looks like the screen shot shown on this site. I then saved it to the same location as per the instructions, using the same name (BooktoDocument.jsx). So I am not sure what else to do.
I have one suggestion. Your instructions start out by saying to open the ExtendScript Toolkit 2. It would be nice if you tell the reader where this utility is located. It may be known to other users but I could not locate it until I happened to ask an Adobe person via an email when I posted a bug report for the Indexing problem.
October 3rd, 2007 at 3:31 pm
Go to the original forum:
http://forum.adobe.com/webx/.3bc3c645!skip=0
then take post 33
there is the original script which is running
October 3rd, 2007 at 6:43 pm
Thank you Rainer for the suggestion. However, when I click on your link I get the error “Internet Explorer cannot display this webpage.” I have been trying for awhile and don’t know if the site is having some problems, or there is something wrong with the address. i.e.,I see other characters at the end of the addres line which are not highligted, i.e. !skip=0 What do those mean? My internet connection seems fine since I can go to other sites.
October 3rd, 2007 at 11:57 pm
I finally found my way back to the original forum and copied and pasted the script there. This seemed to work fine. Thank you.
October 4th, 2007 at 3:15 pm
I’m glad you got it worked out, sorry you had such trouble! I did go back and remove all the spaces from the script. Maybe that was the problem? Not sure.