Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Silent print an embedded PDF

I have a web page with embedded PDF on it. My code looks like this:

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

I have this javascript code for print my PDF:

function printDocument(documentId) {

    //Wait until PDF is ready to print    
    if (typeof document.getElementById(documentId).print == 'undefined') {

        setTimeout(function(){printDocument(documentId);}, 1000);

    } else {

        var x = document.getElementById(documentId);
        x.print();
    }
}

When this code is executed Acrobat plug-in opens the well-known print dialog. Something like this:

PrintDialog

Two questions:

  • How to improve the way to detect that PDF is loaded and ready for print?
  • How to avoid showing print dialog?

A little more info about my system:

OS: Windows XP

Browser: Internet Explorer 7

PDF Plugin: Acrobat Reader 9

like image 600
sourcerebels Avatar asked Jun 10 '09 13:06

sourcerebels


2 Answers

You are not going to be able to print silently with plain old JavaScript. How would you like your printer to start printing out 100000000 pages of all black. Not a good thing. If you want to print silently and have it work for Internet Explorer only, there are ActiveX controls out there that can do it. This requires higher security settings for your page and for your users to really trust your site.

like image 65
epascarello Avatar answered Oct 10 '22 19:10

epascarello


This is possible in a trusted, Intranet environment.

<object id="pdfDoc" style="position:absolute;z-index:-1;" name="pdfDoc" classid="clsid:CA8A9780-280D-11CF-A24D-444553540000" width="900px" height="100%">
        <param name="SRC" value="yourdoc.pdf" />
    </object>

<input type="button" ... onclick="pdfDoc.printAll();" />

This will bypass the print dialog and send directly to the default printer.

like image 5
PushCode Avatar answered Oct 10 '22 20:10

PushCode