Skip navigation
Currently Being Moderated

AIR and PDF showing/silent printing

May 26, 2010 8:09 AM

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

 

Thanks for any ideas.

 
Replies
  • Chris Campbell
    9,456 posts
    May 4, 2010
    Currently Being Moderated
    May 26, 2010 4:12 PM   in reply to Zolotoj

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 20, 2010 9:34 AM   in reply to Chris Campbell

    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

     
    |
    Mark as:
  • Chris Campbell
    9,456 posts
    May 4, 2010
    Currently Being Moderated
    Aug 20, 2010 10:53 AM   in reply to worldwisewebs

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 20, 2010 11:38 AM   in reply to Chris Campbell

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 20, 2010 9:06 PM   in reply to worldwisewebs

    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);
         }
    }
    
     
    |
    Mark as:
  • Chris Campbell
    9,456 posts
    May 4, 2010
    Currently Being Moderated
    Aug 23, 2010 11:51 AM   in reply to worldwisewebs

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 17, 2011 6:46 PM   in reply to Zolotoj

    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!

     

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 19, 2012 6:44 AM   in reply to Zolotoj

    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

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points