9 Replies Latest reply on Jul 19, 2012 6:44 AM by Onyrix

    AIR and PDF showing/silent printing

    Zolotoj Level 3

      Is there a way of showing PDF in an AIR application? What about PDF  silent printing?


      Thanks for any ideas.

        • 1. Re: AIR and PDF showing/silent printing
          chris.campbell Adobe Employee


          AIR is able to render PDF if the user has Adobe Reader or Adobe Acrobat (version 8+) installed. 


          Adding PDF Content


          You might be able to accomplish the printing by following techniques described in Cross-scripting PDF content in an Adobe AIR application and Printing a PDF document from AIR without displaying it or the control bar (using PDF cross-scripting)


          Hope this helps,


          • 2. Re: AIR and PDF showing/silent printing

            Chris -


            If I am understanding correctly, the above links both work using a pdf that has been compiled into the air application.  I need to be able to dynamically pull a list of pdfs from a website, that are then compiled into a list and silently batch printed on the local machine.  Is this possible using the above cross-scripting method, assuming the pdfs contain the proper javascript?


            Also - is there a way to add the javascript dynamically into the pdfs, so the pdf does not have to contain this script before it hits the air app?



            • 3. Re: AIR and PDF showing/silent printing
              chris.campbell Adobe Employee

              I'm not sure if this is possible.  I suspect you should be able to work with a dynamic list of PDF's but I don't know about adding the javascript into the PDF on the fly.  Maybe someone else who has worked with PDF printing can weigh in on how this might be accomplished?


              Moved thread to the Adobe AIR Development forum.



              • 4. Re: AIR and PDF showing/silent printing
                worldwisewebs Level 1

                Thanks for the quick response.




                ^^This may be my answer.  Will post back when I have any results to share after testing some of this stuff.

                • 5. Re: AIR and PDF showing/silent printing
                  worldwisewebs Level 1

                  update: using the javascript injection method described in the links above works fine with dynamically created html elements, and will launch the print window for multiple pdfs ..  Below is my jquery code, it's quick and dirty but it works...  I've got a button with the ID #print_list in my html file and a div with the id #pdf_holder to hold the objects.  There is a dynamically created list of links in teh #pdf_target div.


                  The callPdfFromJavascript() function assumes that the pdf has the corresponding javascript already loaded.  I have modified this function slightly to include the increment variable allowing each object to have a unique ID.

                  See link posted by chris above for the function that goes in the pdf.


                  I still need to figure out how to do this without the objects appearing but getting this far makes me happy


                  $(document).ready(function() {
                       if(air.HTMLLoader.pdfCapability == air.HTMLPDFCapability.STATUS_OK)  
                            air.trace( "PDF content can be displayed" );
                            //print button 
                            $('#print_list').click(function() {
                                 var i='1';
                                 $('#pdfdad_target a').each(function() {
                                      var pdfLink = $(this).attr('href');
                                      var pdfObjectHtml = '<object id="PDFObj'+ i + '" data="'
                                           + pdfLink + '" type="application/pdf"></object>';
                                      //send message to pdf to print
                                      callPdfFunctionFromJavascript('Print', i);
                            air.trace("PDF cannot be displayed. Error code:", HTMLLoader.pdfCapability); 
                  //function that sends print command to pdf
                  function callPdfFunctionFromJavascript(arg, i){
                       air.trace('got this far');
                       var pdfObjectId = "PDFObj" + i;
                       pdfObject = document.getElementById(pdfObjectId);
                       try {
                       catch (e) {
                            alert("Error: \n name = " + e.name + "\n message = " + e.message);
                  • 6. Re: AIR and PDF showing/silent printing
                    chris.campbell Adobe Employee

                    Thanks for giving us the update and sharing your code!  Would be great to know if you're able to fully solve the problem.



                    • 7. Re: AIR and PDF showing/silent printing
                      Zolotoj Level 3

                      Were you able to print a PDF file to a selected in AIR app printer? Could you print with no print dialog at all?



                      • 8. Re: AIR and PDF showing/silent printing
                        worldwisewebs Level 1

                        Actually no we ended up abandoning the project!  The best I was able to do was send a batch to the printers but the user still had to interact with a print dialog and click "print" for each document in the queue.  We were testing this out and the customer decided this was unacceptable and everyone just moved on..


                        It may be possible by now but my understanding is that there are operating system security reasons batch printing is not easy to do from software code.


                        Good luck and post here if you figure it out!



                        • 9. Re: AIR and PDF showing/silent printing

                          here is an article how to open and show and silent print pdf in Windows and Mac OSX with examples (using native commands):