5 Replies Latest reply on Nov 23, 2011 7:17 AM by DirkK20111

    print() command for special documents

    DirkK20111

      Hello,

       

      i have pdf documents with pages labeled like "1-4", "4-55" or "6-17" (Where 6 ist the chapter and 17 the page of the chapter). Those documents are protected by a password to avoid change the file content, but it is allowed to print the document.

       

      Now i wish to have a button in my document which prints all pages between the page with the print button and a previous page with a special, hidden form field "printbeginmark". For example the user presses the button on page "6-22" and the hidden field "printbeginmark" is on page "6-17"- all pages between 6-22 and 6-17 should be printed then. The document can have multiple buttons and begin marks.

       

      I looked at the SDK and developed a first solution- a javascript code executed when pressing the print button:

       

      pagemarker_field_name = "printbeginmark";

       

      current_pagemarker_index = 0;

      nearest_pagemarker_page = null;

      do {

          try {

              current_pagemarker_name = pagemarker_field_name + "." + current_pagemarker_index++;

              current_pagemarker_page = this.getField(current_pagemarker_name).page;

              current_difference = this.pageNum - current_pagemarker_page;

              nearest_difference = this.pageNum - nearest_pagemarker_page;

              if ((nearest_pagemarker_page == null) || ((current_difference < nearest_difference) && (current_difference >= 0))) {

                  nearest_pagemarker_page = current_pagemarker_page;

              }

          } catch (e) {

              current_pagemarker_page = null;

          }

      } while (current_pagemarker_page != null);

       

      if (nearest_pagemarker_page != null) {

          this.print(true, nearest_pagemarker_page, this.pageNum, true);

       

          app.alert({cMsg: "Successfully printed.", cTitle: "Information", nIcon: 3});

      } else {

          app.alert("Could not find start marker '" + pagemarker_field_name + "' for printing.");

      }

       

      That worked very fine for documents with normal page numbering like 1,2,3 and so on. But if a document has page names like "6-17" (Startmarker) and "6-22" (Printbutton) it doesn't work. In the print dialog i can see, that Adobe Acrobat wants to print "6-17 - 6-22". I think it's of the three dashes, one for the page area and the other two within the page names.

       

      So i tried to modify the print command, so that it won't show the user dialog and starts with printing:

       

      ...

      this.print(false, nearest_pagemarker_page, this.pageNum, true);

      ...

       

      That worked very nice- now the correct page area is printed. Problem ist, that the user now cannot change any settings for example to print the page in grey scale or to print multiple pages to one page. If the user selects "print setup" he can configure the printer- the settings are applied if the users presses manually the "print" button in the menue. But unfortunately this doesn't effect the print() command of the button. Next thing i tried was:

       

      ...

      app.execMenuItem("PageSetup");

      this.print(false, nearest_pagemarker_page, this.pageNum, true);

      ...

       

      But it doesn't work too- any printer settings made during app.execMenuItem("PageSetup"); are skipped and were not applied- if i choose manually File-> Printer settings then no of the changes made in the Script are changed.

       

      Now i tried it also with the printParams object, to set the multiple pages mode in the script:

       

      ...

      pp = this.getPrintParams();

      pp.pageHandling = pp.constants.handling.nUp;

      pp.nUpPageOrders = pp.constants.nUpPageOrders.Vertical;

      pp.nUpNumPagesH = 2;

      pp.nUpNumPagesV = 2;

      pp.nUpPageBorder=true;

      pp.nUpAutoRotate=true;

      pp.lastPage = this.pageNum;

      pp.firstPage = nearest_pagemarker_page;

      this.print(pp);

      ...

       

      Doesn't work- the print dialog appears with the page area "6-17 - 6-22" and an error message appears if i want to print. If i set also the interactive mode above via:

       

      ...

      pp.interactive = pp.constants.interactionLevel.automatic;

      ...

       

      Then it works, but the user cannot make any settings to the printer. Is there any chance to display the printer dialoge in this case?

       

      Thank you in Advance,

      Dirk