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

Validate and fix a Book's total page count via script

Participant ,
May 24, 2023 May 24, 2023

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?

TOPICS
How to , Print , Scripting , SDK
710
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

correct answers 1 Correct answer

Community Expert , May 25, 2023 May 25, 2023

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

...
Translate
LEGEND ,
May 24, 2023 May 24, 2023

You need to go through the collection of the documents of the book and read no of pages and check the total. 

 

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 Expert ,
May 24, 2023 May 24, 2023

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);
}
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 Expert ,
May 25, 2023 May 25, 2023

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.

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
Participant ,
May 25, 2023 May 25, 2023

Thanks All! Very much appreciated! I will give these solutions a try and let you know how it goes!

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 Expert ,
May 25, 2023 May 25, 2023

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

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
Participant ,
May 25, 2023 May 25, 2023
LATEST

No worries at all @m1b !

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 Expert ,
May 25, 2023 May 25, 2023

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]).

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