Copy link to clipboard
Copied
Let's say I have a catalog of widgets that I've put together using a book in InDesign. Each manufacturer of widgets is its own document in the book, it looks something like this:
Widget catalog.indb
Widget_intro.indd
Widget_maker_1.indd
Widget_maker_2.indd
Widget_maker_3.indd
Widget_conclusion.indd
Every time I make a change to one of the Widget_maker files, I have to re-export a version of the PDF with Widget_maker_1 and _2, a version with Widget_maker_2 and _3, and a version with Widget_maker_1 and _3.
I want to write a script that'll do all the exporting for me, but I'm having trouble with the bookContents/bookContent bit in ExtendScript. This is what I have so far:
var myBook = app.activeBook;
myBook.exportFile (ExportFormat.PDF_TYPE, File (myBook.filePath+myBook.name.replace(/\.indb/g, "_test_LR.pdf")), false, "[Smallest File Size]", myBook.bookContents, "Book_PDF", false);
I can't figure out how to format whichDocument part, I can only get myBook.bookContents to work, which exports the whole book. Probably some dumb syntax error I'm making, any help is appreciated.
Best,
-Jonathan
Hi Jonathan,
argument 5 in method exportFile() of object book handles the documents that are stored in the book as collection bookContents.
So you need only two of your stored documents? Write them to an array and provide the array as argument.
For example with calling them by name:
...myBook.exportFile
(
ExportFormat.PDF_TYPE ,
File( "/blablabla.pdf" ) ,
false ,
"[Smallest File Size]" ,
[
myBook.bookContents.itemByName( "Widget_maker_1.indd" ) ,
myBook.bookContents.item
Copy link to clipboard
Copied
Hi Jonathan,
argument 5 in method exportFile() of object book handles the documents that are stored in the book as collection bookContents.
So you need only two of your stored documents? Write them to an array and provide the array as argument.
For example with calling them by name:
myBook.exportFile
(
ExportFormat.PDF_TYPE ,
File( "/blablabla.pdf" ) ,
false ,
"[Smallest File Size]" ,
[
myBook.bookContents.itemByName( "Widget_maker_1.indd" ) ,
myBook.bookContents.itemByName( "Widget_maker_2.indd" )
]
/* There are two optional arguments following */
);
See DOM documentation:
Adobe InDesign CS6 (8.0) Object Model JS: Book
Adobe InDesign CS6 (8.0) Object Model JS: BookContent
Regards,
Uwe
Copy link to clipboard
Copied
Fantastic, as I guessed my syntax for the array was wrong. Thanks!
On another note, would it be possible to truncate using variables? I have a lot of items, so it would be nice if my array could look something like this:
var widgetOne = myBook.bookContents.itemByName( "Widget_maker_1.indd" )
var widgetTwo = myBook.bookContents.itemByName( "Widget_maker_2.indd" )
var widgetThree = myBook.bookContents.itemByName( "Widget_maker_3.indd" )
- myBook.exportFile
- (
- ExportFormat.PDF_TYPE ,
- File( "/blablabla.pdf" ) ,
- false ,
- "[Smallest File Size]" ,
- [
- widgetOne,
- widgetTwo
- ]
- /* There are two optional arguments following */
- );
Copy link to clipboard
Copied
Hi Jonathan,
at one point you have to declare the variables.
You can use them as shown in the snippet where you declared them at the top and used them with the method below.
Another thing:
You could also do this with an index number ( starting to count with 0 ) instead of a name. That would be useful if you have changing contents of a book or several books where you use always, say the second item and the third item of the collection of bookContents. Regardless of their names.
var widgetOne = myBook.bookContents[1]; // Second item of the collection
var widgetTwo = myBook.bookContents[2]; // Third item of the collection
You could also test itemByRange() if the items are ordered in a row; that would return an array of bookContent items.
var widgetsToExport = myBook.bookContents.itemByRange( 1,2 ); // Returns Array !
myBook.exportFile
(
ExportFormat.PDF_TYPE ,
File( "/blablabla.pdf" ) ,
false ,
"[Smallest File Size]" ,
widgetsToExport
/* There are two optional arguments following */
);
Regards,
Uwe
Copy link to clipboard
Copied
Fantastic, thank you for the info. I'm going to look into learning JavaScript proper because this is so powerful.