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

    AIR and PDF showing/silent printing

    Zolotoj Community Member

      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

          Hi,

          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,

          Chris

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

            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?

             

            Thanks

            • 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.

               

              Chris

              • 4. Re: AIR and PDF showing/silent printing
                worldwisewebs Community Member

                Thanks for the quick response.

                 

                http://www.cetola.net/?p=20

                 

                ^^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 Community Member

                  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>';
                                      
                                      $('#pdf_holder').html();
                                                
                                      $('#pdf_holder').append(pdfObjectHtml);
                                      
                                      air.trace(i);
                                      
                                      //send message to pdf to print
                                      callPdfFunctionFromJavascript('Print', i);
                  
                                      i++;
                                 });
                                 
                            });
                       } 
                       else  
                       { 
                            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);
                       
                       air.trace(pdfObjectId);
                       
                       try {
                            pdfObject.postMessage([arg]);
                       } 
                       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.

                     

                    Chris

                    • 7. Re: AIR and PDF showing/silent printing
                      Zolotoj Community Member

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

                       

                      Thanks

                      • 8. Re: AIR and PDF showing/silent printing
                        worldwisewebs Community Member

                        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
                          Onyrix Community Member

                          here is an article how to open and show and silent print pdf in Windows and Mac OSX with examples (using native commands):
                          http://www.onyrix.com/2012/04/adobe-air-pdf-silent-print-with-acrobat-reader/

                          bye
                          d