10 Replies Latest reply on Oct 13, 2011 7:06 AM by Liefie2000

    Javascript: Passing values to Print Dialog

    fshuja Level 1

      hi,

       

      I have a PDF page containg 8 pages. On first page there is a Print button and some select boxes (Page1, Page2, .. Page8)

      I want to open Print Dialog with page numbers already set from the select boxes.

      Example: If i have checked Page1, Page 4 check boxes then Print Dialog should show the values in  Print Rang > Pages [1,4]

       

      how can i do this using javascript?

      Please help me out

       

      thanks

      Faraz

        • 1. Re: Javascript: Passing values to Print Dialog
          Niall O'Donovan Level 7

          Hi,

           

          In LC Designer you do not (as far as I know) have as much access to print properties than you do in Acrobat (which uses printParam).

           

          The XFA print command had eight parameters. The second and third parameters specify the start page and finish page for printing, based on a zero numbering system.

           

          I think that you will be able to specify a start page and an end page using javascript (eg 3-5). But it would be more complicated to specify a range with gaps (eg 3-4,6,8).

           

          The standard XFA command in a print button is:

           

          xfa.host.print(1, "0", (xfa.host.numPages -1).toString(), 0, 0, 0, 0, 0);

           

          The third parameter is looking at the total number of pages. You can change this to refer to values of objects in your form that relate to the start and finish pages to be printed.

           

          xfa.host.print(1, (NumericField1.rawValue -1).toString(), (NumericField2.rawValue -1).toString(), 0, 1, 0, 0, 0);

           

          Or you could set up an if statement to look at a number of objects in the form and determine the start and finish pages.

           

          I think this is as far as you can take it. The only other alternative is calling the print command a number of times to deal with gaps in the printing range, but this may become tiresome for the user.

           

          Good luck,

           

          Niall

          • 2. Re: Javascript: Passing values to Print Dialog
            fshuja Level 1

            Can u please tell me the exact command i need to print pages 3-4,6,8

             

            I tried like this but its not working

            xfa.host.print(1, "3,4,6,8", "4", 0, 1, 0, 0, 0);

             

             

            thanks

            Faraz

            • 3. Re: Javascript: Passing values to Print Dialog
              Niall O'Donovan Level 7

              Hi Faraz,

               

              That's the problem, you cannot specify a print range with gaps.

               

              xfa.host.print(1, "0", "7", 0, 1, 0, 0, 0);

               

              The second parameter specifies the start page (based on a zero numbering system). Therefore "0" will print from page 1 of the form.

               

              The third parameter specifies the last page to be printed. Therefore "7" will print page 8 of the form.

               

               

              Here is a sample of the only workaround I can think of. Basically the button opens the print set up dialogue (not the standard print window). This allows the user to select the correct printer and settings. Then the script looks at each page in turn and prints is as a standalone print job. If you look at the print command you will see that the first parameter is set to "0", this is to print the page without displaying the print dialogue. The fourth parameter is now set to "1" to prevent the user cancelling the print job. If you look at the help file you will get a full description of the print command and all eight parameters.

               

              xfa.host.print(0, "0", "0", 1, 1, 0, 0, 0);

               

              Hope that helps,

               

              Niall

              • 4. Re: Javascript: Passing values to Print Dialog
                Jono Moore Level 4

                A workaround I've seen mentioned before is to hide the pages you don't want before printing and make them visible again after printing.

                1 person found this helpful
                • 5. Re: Javascript: Passing values to Print Dialog
                  Niall O'Donovan Level 7

                  Duh... Jono is right and his solution would also work if the user printed from the Acrobat print menu item.

                   

                  If you delete the button in the example and have the following in the prePrint event of the checkbox on each page (just change the page reference:

                   

                  if (this.rawValue == 0) // not checked
                  {
                       page1.presence = "hidden"; // the SOM reference will have to relate to each page reference
                  }
                  else
                  {
                       page1.presence = "visible";
                  }
                  

                   

                  Then in the postPrint event you would have just a single line to make sure that the page is made visible again:

                   

                  page1.presence = "visible";

                   

                  Sorry about the mis-direction. Jono's solution is much simpler to implement. Just note you can't hide all pages, so that if none of the pages are ticked, then a single blank page will print.

                   

                  Good luck,

                   

                  Niall

                  • 6. Re: Javascript: Passing values to Print Dialog
                    Liefie2000 Level 1

                     

                    2009-11-15 Printing different pages.pdf

                    This pdf doesn't work. I select the pages I want to print and click the print button and nothing happens.

                    • 7. Re: Javascript: Passing values to Print Dialog
                      Liefie2000 Level 1

                      I tried your suggestion, but it always says "failed to print, no pages selected." Even when I have the box checked.

                      • 8. Re: Javascript: Passing values to Print Dialog
                        Liefie2000 Level 1

                        I've tried hiding the pages, but I still get 3 blank pages printing eventhough I've selected other pages to print.

                        • 9. Re: Javascript: Passing values to Print Dialog
                          Niall O'Donovan Level 7

                          Hi,

                           

                          Sorry for the delay.

                           

                          I have had a look at the form and for some reason the script was missing from the checkbox on all but the first page. I have corrected this and hopefull the updated example will give you a direction:

                          https://acrobat.com/#d=BiyCjZJoeK9rmZDcZLXIwA.

                           

                          Hope that helps,

                           

                          Niall

                          • 10. Re: Javascript: Passing values to Print Dialog
                            Liefie2000 Level 1

                            Document wasn't coming up. We settled on individual print dialog boxes for each set of pages/documents the want to print.