Ad Code

Responsive Advertisement

Print PDF directly from JavaScript

This question demonstrates an approach that might be helpful to you: Silent print a embedded PDF

It uses the <embed> tag to embed the PDF in the document:

<embed
 type="application/pdf"
 src="path_to_pdf_document.pdf"
 id="pdfDocument"
 width="100%"
 height="100%">
</embed>

Then you call the .print() method on the element in Javascript when the PDF is loaded:

function printDocument(documentId) {
 var doc = document.getElementById(documentId);
 //Wait until PDF is ready to print 
 if (typeof doc.print === 'undefined') { 
 setTimeout(function(){printDocument(documentId);}, 1000);
 } else {
 doc.print();
 }
}

You could place the embed in a hidden iframe and print it from there, giving you a seamless experience.

Post a Comment

0 Comments

Close Menu