8 Replies Latest reply on Aug 18, 2016 5:37 PM by BobLevine

    Print every nth page from a book

    BobLevine MVP & Adobe Community Professional

      I have a client in need of a script to print every nth page in an InDesign book. The book could be more than 20,000 pages so manually entering page ranges isn't going to work.  Has anyone written anything like?

        • 1. Re: Print every nth page from a book
          TᴀW Adobe Community Professional & MVP

          Hi Bob,

           

          You do specifically mean a book (indb) and not a document, right?

           

          Ariel

          • 2. Re: Print every nth page from a book
            BobLevine MVP & Adobe Community Professional

            Yes, indeed. A very, very large book.

             

            Background: It’s a merge of documents that needed barcodes. I used Barcode Maker and DateLinker from Teacup Software. Book could have 200 or more documents with 200 pages or so.

            • 3. Re: Print every nth page from a book
              TᴀW Adobe Community Professional & MVP

              So, next question: Do you want each page a separate PDF file, or one large combined PDF?

               

              If a single PDF, the fact is, I don't think it's possible -- not from a book. From a document, yes, but from a book, you can see that the Page Range field in the Print dialog of a book is grayed out. If it's grayed out in the UI, it can't be done in a straightforward way with scripting, either.

               

              A script could obviously create many PDF files, but they would then need to be combined in Acrobat, in which case it would probably be simpler to create one large PDF file of the entire book, and then extract the required pages in Acrobat.

               

              But perhaps you do want separate files for each page?

              • 4. Re: Print every nth page from a book
                BobLevine MVP & Adobe Community Professional

                Don’t need a PDF, we can print directly from InDesign.

                • 5. Re: Print every nth page from a book
                  TᴀW Adobe Community Professional & MVP

                  Right, of course. Don't know why that didn't sink in.

                   

                  Okay, so that makes it doable. Try this (at your own risk!):

                   

                  var b = app.activeBook;
                  var f = b.bookContents;
                  var d = []; // The book documents
                  var p = []; // All the pages
                  var q = app.printerPresets.itemByName("test"); // Type the name of the printer preset here
                  if (!(q.isValid)){
                    alert("The printer preset you have selected cannot be found,");
                    exit();
                  }
                  var s = 1; // The start page (absolute numbering)
                  var n = 5; // Print every nth page
                  var i;
                  for (i = 0; i < f.length; i++){
                    d.push(app.open(f[i].fullName));
                    p = p.concat(d[i].pages.everyItem().getElements());
                    d[i].printPreferences.activePrinterPreset = q;
                    d[i].printPreferences.printBlankPages = true;
                  }
                  for (i = s; i < p.length; i += n){
                    d = p[i].parent.parent;
                    d.printPreferences.pageRange = "+" + (p[i - 1].documentOffset + 1);
                    d.print(false);
                  }
                  

                   

                  In line 5, type the name of the printer preset you want to use.

                  In line 10, set the start page.

                  In line 11, set the interval.

                   

                  The script will first open ALL the documents in the book, simultaneously. I hope that won't grind ID to a halt in your case. They could, obviously, be opened and closed as needed, but for the script it's simpler this way. It also leaves them open at the end.

                   

                  Then, it sends each page to the printer. In my minimal testing, I noticed that trying to print blank pages causes an error unless specifically allowed (hence line 17). There may be other such things that cause an error.

                   

                  The only error checking in this script is to see whether the print preset actually exists.

                   

                  Good luck!

                  Ariel

                  • 6. Re: Print every nth page from a book
                    BobLevine MVP & Adobe Community Professional

                    I’ll forward this to the client. Thanks!

                    • 7. Re: Print every nth page from a book
                      TᴀW Adobe Community Professional & MVP

                      Just make sure to tell them that it's pretty raw and untested!

                       

                      Also, I forgot to mention that it assumes that an InDesign book is open.

                       

                      If there are any updates to the script, they will be posted here: http://www.id-extras.com/print-every-nth-page-from-an-indesign-book

                       

                      Ariel

                      • 8. Re: Print every nth page from a book
                        BobLevine MVP & Adobe Community Professional

                        Thanks!