12 Replies Latest reply on May 30, 2014 3:46 AM by try67

    Print multiple page ranges based on radio button group choices

    roo_roo

      Hi ... I have a PDF that is a combined application form made up of 6 separate forms. On the front page, I have 6 groups of "Yes / No" radio buttons.

       

      If the radio button for one or more of these groups is selected as "Yes" then when the Print button (on the page) is clicked then the appropriate page ranges will print.

      It is desireable, though not essential, for these to be printed in one print job.

      The Code I have been adjusting to try and achieve the result is below but I have tied myself in knots now and any help would be greatly appreciated:

       

      Many thanks

       

      
      
      //<AcroForm>
      //<ACRO_source>PrntForms:Annot1:MouseUp:Action1</ACRO_source>
      //<ACRO_script>
      /*********** belongs to: AcroForm:PrntForms:Annot1:MouseUp:Action1 ***********/
      var nButton = app.alert({
      cMsg: "Your selected forms will be sent to your default printer.\n\nIf you require to print to an alternative printer, press cancel and select 'Print' from the 'File' menu.",
      cTitle: "Submit Forms for Printing?",
      nIcon: 1, nType: 1
      });
      // array for button responses
      //var aResponse = new Array("OK", "Cancel");
      
      if(nButton == 1) 
      {    this.print({ bUI: false, bSilent: true, bShrinkToFit: true, nStart: 1, nEnd: 1 });
      } else
      if(nButton == 0) 
      {    this.Exit
      }
      
      var a_app;
      if(this.getField("AppForm1”).value=="Yes"){
          a_app = "1, 1";
      } else a_app = "0, 0"
      
      var b_app;
      if(this.getField(“AppForm2”).value=="Yes"){
          b_app = "2, 2";
      } else b_app = "0, 0"
      
          var pp = this.getPrintParams();
                pp.interactive = pp.constants.interactionLevel.full;
                pp.printRange=[[a_app], [b_app]];
                this.print(pp);
      //</ACRO_script>
      //</AcroForm>
      
      
        • 1. Re: Print multiple page ranges based on radio button group choices
          gkaiseril MVP & Adobe Community Professional

          Have you looked at the JavaScript file for errors?

           

          Have you looked at the "print" method of the "doc" object in the Acrobat JavaScript API Reference?

           

          Pay attention to the note that reads:

           

          Note: (Acrobat 6.0) When printing to a file, the path must be a safe path (see Safe path). The print method will not overwrite an existing file.

          (Acrobat 7.0) Non-interactive printing can only be executed during batch, console, and menu events. Printing is made non-interactive by setting bUI to false or by setting the interactive property to silent, for example:

          • 2. Re: Print multiple page ranges based on radio button group choices
            try67 MVP & Adobe Community Professional

            You're not specifying the printRange parameter correctly. It needs to be consisted of an array containing arrays of 2 digits. Yours consists of an array containing arrays with a string in them.

            • 3. Re: Re: Print multiple page ranges based on radio button group choices
              roo_roo Level 1

              Thanks both for your responses.

               

              Thanks Gilad D... I know the print rage is currently set as a string, but I was trying to utilise my limited knowledge to be able to dynamically set the print ranges.

              Eg:

              Radio Button Group 1 (RBG1) = pages 1 to 10

              Radio Button Group 2 (RBG2) = pages 11 to 15

              Radio Button Group 3 (RBG3) = pages 16 to 20

              Radio Button Group 4 (RBG4) = pages 21 to 25

              Radio Button Group 5 (RBG5) = pages 26 to 28

              Radio Button Group 6 (RBG6) = pages 29 to 35

               

              So I need an if, then else statement that is capable of populating the Print Range

               

              If RBG1 = "Yes",

              If RBG2 = "No",

              If RBG3 = "No",

              If RBG4 = "Yes"

              If RBG5 = "No"

              If RBG6 = "Yes"

               

              then the print range would be populated with:

               

              pp.printRange=[[1,10],[21,25],[29,35]];
              

               

              I hope that clarifies and apologies for any prior confusion.

              Thanks again for your responses both.

              • 4. Re: Print multiple page ranges based on radio button group choices
                try67 MVP & Adobe Community Professional

                So you can use something like this:

                 

                var printRanges = [];

                if (this.getField("RBG1").value=="Yes") printRanges.push([0,9]); // remember the pages are zero-based

                if (this.getField("RBG2").value=="Yes") printRanges.push([10,14]);

                // etc.

                 

                And finally:

                var pp = this.getPrintParams(); 

                pp.interactive = pp.constants.interactionLevel.full; 

                pp.printRange=printRanges;

                this.print(pp);

                • 5. Re: Re: Print multiple page ranges based on radio button group choices
                  try67 MVP & Adobe Community Professional

                  Actually, the last part should be something like this (I tried to edit the code but it's buggy):

                   

                  if (printRanges.length>0) {

                      var pp = this.getPrintParams();

                      pp.interactive = pp.constants.interactionLevel.full;

                      pp.printRange=printRanges;

                      this.print(pp);

                  } else app.alert("No page ranges are selected.");

                  • 6. Re: Re: Print multiple page ranges based on radio button group choices
                    roo_roo Level 1

                    Hi Gilad D

                    From my knowledge of Javascript (some but limited) that looks great and makes sense to me; so thank you.

                    I'll put it in and test it later and then mark the conversation accordingly.

                    Again, many thanks.

                    • 7. Re: Re: Re: Print multiple page ranges based on radio button group choices
                      roo_roo Level 1

                      Hi Gilad D

                       

                      The 'printRanges.push' function works well on my Mac using Adobe Acrobat Pro XI however when it is used on the systems that the form users will be working on (which runs Adobe Reader 9.4.0.195) the ranges are not pushed to the printer dialogue box and the 'printRange'

                       

                      in the dialogue is still selecting the 'All Pages' radio button.

                       

                      Is the printRanges.push function a new and non-backwards-compatible function or is my code the problem

                       

                      :

                       

                      
                      //<AcroForm>
                      //<ACRO_source>PrntForms:Annot1:MouseUp:Action1</ACRO_source>
                      //<ACRO_script>
                      /*********** belongs to: AcroForm:PrntForms:Annot1:MouseUp:Action1 ***********/ 
                      
                      var printRanges = [];
                      if (this.getField("RBG10").value=="Yes") printRanges.push([0,2]);
                      if (this.getField("RBG1").value=="Yes") printRanges.push([3,18]);
                      if (this.getField("RBG2").value=="Yes") printRanges.push([19,27]);
                      if (this.getField("RBG3").value=="Yes") printRanges.push([28,38]);
                      if (this.getField("RBG4").value=="Yes") printRanges.push([39,42]);
                      if (this.getField("RBG5").value=="Yes") printRanges.push([43,54]);
                      if (this.getField("RBG6").value=="Yes") printRanges.push([14,16]);
                      if (this.getField("RBG7").value=="Yes") printRanges.push([55,56]);
                      if (this.getField("RBG8").value=="Yes") printRanges.push([57,65]);
                      if (this.getField("RBG9").value=="Yes") printRanges.push([66,71]);
                      if(printRanges.length>0){
                         var pp = this.getPrintParams();
                                  pp.interactive = pp.constants.interactionLevel.full;
                                  pp.printRange=printRanges;
                                  this.print(pp);
                      }else app.alert("No page ranges are selected"); 
                      //</ACRO_script> 
                      //</AcroForm>
                      

                       

                      Any assistance is greatly appreciated.

                      Many thanks

                      • 8. Re: Print multiple page ranges based on radio button group choices
                        try67 MVP & Adobe Community Professional

                        The printRange property of the PrintParams object was only introduced in

                        version 11. It will not work in any previous version of Acrobat/Reader.

                        • 9. Re: Re: Print multiple page ranges based on radio button group choices
                          roo_roo Level 1

                          Thanks for the confirmation, Gilad D; is there anyway of utilising / adapting the other method method of defining a print range, as shown below, using the nStart: and nEnd functions?

                          Again, many thanks.

                           

                          
                          if(nButton == 1)      
                          {    this.print({ bUI: false, bSilent: true, bShrinkToFit: true, nStart: 1, nEnd: 1 });   
                          } else  
                          if(nButton == 0)    
                          {    this.Exit   
                          }
                          
                          • 10. Re: Re: Print multiple page ranges based on radio button group choices
                            try67 MVP & Adobe Community Professional

                            Sure, you can use that, but you'll need to send a separate print command for each range of pages.
                            It's possible to write a script that will smartly combine all the ranges to a small amount as possible, but it will still probably be more than one command.

                             

                            PS. this.Exit is not a valid command.

                            • 11. Re: Re: Re: Print multiple page ranges based on radio button group choices
                              roo_roo Level 1

                              Hi Gilad D    

                              I've come up with the below which does successfully send the requested jobs to the print queue; however, you mentioned a way of condensing the code ... is there a way of bringing up the Print Dialogue box (bUI: true) only once and setting the options for double sided, colour etc that will then apply to the requested print pages?

                               

                              Many thanks

                               

                              if(nButton == 1){ 
                                  if(this.getField("RBG10").value=="Yes") this.print({ bUI: true, bSilent: false, bShrinkToFit: true, nStart: 0, nEnd: 2 });
                                  if (this.getField("RBG1").value=="Yes") this.print({ bUI: true, bSilent: false, bShrinkToFit: true, nStart: 3, nEnd: 18 });
                                  if (this.getField("RBG2").value=="Yes") this.print({ bUI: true, bSilent: false, bShrinkToFit: true, nStart: 19, nEnd: 27 });
                                  if (this.getField("RBG3").value=="Yes") this.print({ bUI: true, bSilent: false, bShrinkToFit: true, nStart: 28, nEnd: 38 });
                                  if (this.getField("RBG4").value=="Yes") this.print({ bUI: true, bSilent: false, bShrinkToFit: true, nStart: 39, nEnd: 42 });
                                  if (this.getField("RBG5").value=="Yes") this.print({ bUI: true, bSilent: false, bShrinkToFit: true, nStart: 43, nEnd: 54 });
                                  if (this.getField("RBG6").value=="Yes") this.print({ bUI: true, bSilent: false, bShrinkToFit: true, nStart: 14, nEnd: 16 });
                                  if (this.getField("RBG7").value=="Yes") this.print({ bUI: true, bSilent: false, bShrinkToFit: true, nStart: 55, nEnd: 56 });
                                  if (this.getField("RBG8").value=="Yes") this.print({ bUI: true, bSilent: false, bShrinkToFit: true, nStart: 57, nEnd: 65 });
                                  if (this.getField("RBG9").value=="Yes") this.print({ bUI: true, bSilent: false, bShrinkToFit: true, nStart: 66, nEnd: 71 });
                              } else
                              if(nButton == 0) 
                              {    app.alert("Your forms will not print.");
                              }
                              
                              • 12. Re: Re: Re: Print multiple page ranges based on radio button group choices
                                try67 MVP & Adobe Community Professional

                                Well, that code can be improved upon (by attempting to combine the ranges into as few as possible), but it should work as well.

                                The answer to your other question is no, I'm afraid.