1 Reply Latest reply on Dec 9, 2013 11:19 AM by Sergey Anosov

    javascript print pdf + multi-page pdf for duplex printing

    bd@masha

      It’s not pretty, but it works.

      I’ve searched a lot for a script like this but had to do it myself.

      I use postage software to print postcards (2000+ a pop) for promotional mailers. I print to a PDF file (just started using NovaPDF after using Acrobat Pro (v7) for several years. Why? Because I lost over $100 in printed postage a long time ago when my computer/printer failed (and it’s a real pain getting them to give a refund).

      This script will take a ‘Message side’ PDF (page 1), and a (multi-page) PDF for page 2 (eg: my PDF file of printed addresses with postage), and print, in duplex (if your printer will), all your postcards. It’s fairly self explanatory, but I’ll add: it allows you to set printer-specific parameters on 1st page printed, then automatically uses same for rest.

      (I use it for other jobs, too, not just postcards)

      Hope someone finds it useful. Modify away...

       

       

      // "duplex-003.js"

      /*

          2 pages only

          page 1 (0) =  Picture(s) PDF

          page 2 (1) = Mailer PDF (multipage)

          we cycle thru page 2 pdf pages

      */

       

       

      var myDoc = app.activeDocument;

      var myPages = myDoc.pages;

       

       

      // p0 = base page

      var p1 = myPages[1];

      var p2 ;

      var Grfx1 = p1.allGraphics[0];

      var GrfxProp1 = p1.allGraphics[0].properties;

      var indexpdf = p1.allGraphics[0].pdfAttributes.pageNumber;

       

       

      // set print box parameters for first print

      var printpagerange = "1,2";

                myDoc.printPreferences.pageRange = printpagerange;

                myDoc.print(true,undefined);

       

       

      // pdf page number starts at 1, not 0

      printpagerange = "1,3";

      var filepath = GrfxProp1.itemLink.filePath;

      while (1) {

          indexpdf++;

          app.pdfPlacePreferences.pageNumber = indexpdf;

          p2 = myPages.add();

          p2.place(filepath);

          if(indexpdf != p2.allGraphics[0].pdfAttributes.pageNumber) {

              p2.remove();

              break;

          }

          myDoc.printPreferences.pageRange = printpagerange;

                myDoc.print(false,undefined);

          p2.remove();

      }

       

       

       

       

      <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< OR you can create a file to print later (faster but larger) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

      // "duplex-003.js" -- create file

        /*

          2 pages only

          page 1 (0) =  Picture(s) PDF

          page 2 (1) = Mailer PDF (multipage)

          we cycle thru page 2 pdf pages

      */

      var myDoc = app.activeDocument;

      var myPages = myDoc.pages;

        // p0 = base page

      var p0 = myPages[0];

      var p1 = myPages[1];

      var p2 ;

      var Grfx1 = p1.allGraphics[0];

      var GrfxProp1 = p1.allGraphics[0].properties;

      var indexpdf = p1.allGraphics[0].pdfAttributes.pageNumber;

        var filepath = GrfxProp1.itemLink.filePath;

       

      while (1) {

          indexpdf++;

          app.pdfPlacePreferences.pageNumber = indexpdf;

          p2 = p0.duplicate(LocationOptions.atEnd,undefined);

          p2 = myPages.add();

          p2.place(filepath);

          if(indexpdf != p2.allGraphics[0].pdfAttributes.pageNumber) {

              p2.remove();

              break;

          }

      }

        • 1. Re: javascript print pdf + multi-page pdf for duplex printing
          Sergey Anosov Level 1

          Hi!

          Maybe this script will be helpful:

          https://sites.google.com/site/dtpscripting/indesign-scripts/imposemultipage-jsx

          In fact it does not give a direct solution of your task, but it can help. For example you can create a Master-spread containing a "non-personalized" page and a page with a text frame to place "personalized" PDF-pages in. An obvious problem is the numbering inside the text frames. But it is solvable too.

          You can create a text file in a spreadsheet application such as MS Excel, containing a column of numbers for "personalized" PDF-pages using increment functions for cells. Then save as/export that as a text file and place in the InDesign document using "auto-flow" with Shift key. The main thing is: the Paragraph style in the text frame on Master-spread must contain in "Keep options" the option "Start in next frame".  After that use this script to break the thread into separate text frames:

          https://sites.google.com/site/dtpscripting/indesign-scripts/breakstory

          or SplitStory.

          So you will have a "template" containing spreads with "non-personalized" pages and pages with text frames containing numbers for "personalized" PDF-pages.

          Finally run the first script ImposeMultiPage.jsx using created paragraph style for numbers.