Copy link to clipboard
Copied
I am working on a process to automate the production of a multiple directories. As part of that process I have built a script that assembles my books and exports them to PDF. However, I need to make sure that the total page count of each book is a multiple of four(4) for printing purposes.
I know how to get the page count of an individual document, but I have not found a good way to get the total page count of a book. All of the documentation on Preflight scripting appears to be specific to a single document.
Ideally, if the page count is not a multiple of 4, the script would add extra pages to the last document in the book as well..
Any suggestions?
It's not as simple as that, Mark. documentPageRange returns a string, which can be a single page number or a range, as in 10-20. But you can have roman numbers as well (i-xi), or a mix, so keep thing funny (iii-12). So you have to open each document and get the page count in each document, as Robert suggested or not open any document and calculate the page extent of each document from its page range.
Robert's method is easy to script and is relatively quick (especially if you don't show the do
...Copy link to clipboard
Copied
You need to go through the collection of the documents of the book and read no of pages and check the total.
Copy link to clipboard
Copied
Hi @Ben Ross - KP, here's something to get you started for now. You can look at the API for Book and BookContent, too.
- Mark
var book = app.books[0];
if (!book)
return;
for (var i = 0; i < book.bookContents.length; i++) {
var bc = book.bookContents[i];
$.writeln('bc.documentPageRange = ' + bc.documentPageRange);
}
Copy link to clipboard
Copied
It's not as simple as that, Mark. documentPageRange returns a string, which can be a single page number or a range, as in 10-20. But you can have roman numbers as well (i-xi), or a mix, so keep thing funny (iii-12). So you have to open each document and get the page count in each document, as Robert suggested or not open any document and calculate the page extent of each document from its page range.
Robert's method is easy to script and is relatively quick (especially if you don't show the documents). The second method is not so easy to implement but is very quick. It's an old script, see attached. I used the txt file type because jsx isn't allowed. Change it back to jsx before using it.
P.
Copy link to clipboard
Copied
Thanks All! Very much appreciated! I will give these solutions a try and let you know how it goes!
Copy link to clipboard
Copied
Thanks Peter. You are right of course. I meant to post a quick answer that might get the ball rolling without providing a complete answer, but I see that what I posted was somewhat misleading. Oops, sorry guys.
- Mark
Copy link to clipboard
Copied
No worries at all @m1b !
Copy link to clipboard
Copied
I also wondered if Book.repaginationOption might be a factor. For example, I don't know what happens if a book document [1] ends on, say, an even page while the book's repagination option is RepaginateOption.NEXT_EVEN_PAGE. Does it add one blank page to book document [1] when a second document is added to the book? If not, then you would need to add that page to your total (and maybe even explicitly add it to document [1]).
Find more inspiration, events, and resources on the new Adobe Community
Explore Now