Is there a way of showing PDF in an AIR application? What about PDF silent printing?
Thanks for any ideas.
Hi,
AIR is able to render PDF if the user has Adobe Reader or Adobe Acrobat (version 8+) installed.
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
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
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
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);
}
}
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!
![]()
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
North America
Europe, Middle East and Africa
Asia Pacific