1

In my app, I want to print a PDF file that resides in iframe. Here is my code ..

<iframe src="pdf/output.pdf" id="pdfFrame"></iframe>

And here is the script to print the pdf..

document.getElementById("pdfFrame").focus();
document.getElementById("pdfFrame").contentWindow.print();

The code above works fine but It opens a windows popup before printing. But as per my requirement I want direct laser print without opening the popup.

Is there any way to do this ???

Gunjan Shah
  • 5,088
  • 16
  • 53
  • 72
  • 2
    No you can't, there's no way to invoke the printer without user intervention. I'd be pissed off if some website started printing stuff without even a chance for me to change settings. – Ruan Mendes Apr 19 '13 at 05:33
  • Thanks for the answer Juan Mendes. As per one post on stack overflow, we can do it using vb script .. please refer this url : http://stackoverflow.com/questions/1096862/print-directly-from-browser-without-print-popup-window – Gunjan Shah Apr 19 '13 at 06:24
  • But VB script is new for me,can you please tell me, in above link... how can i use vb script to print a PDF which resides in an iframe ? – Gunjan Shah Apr 19 '13 at 06:26
  • Another option is using Chrome kiosk printer mode – Dustin Graham Dec 19 '14 at 22:06

1 Answers1

0

The only way to bypass the print dialog is to tweak settings in IE and to write some VBScript.

See Bypass Printdialog in IE9

It only works in IE9, if you can change every client's ActiveX settings. Really should only be used in an intranet scenario where you control the clients.

<script language="VBScript">
    sub Print()
        OLECMDID_PRINT = 6
        OLECMDEXECOPT_DONTPROMPTUSER = 2
        OLECMDEXECOPT_PROMPTUSER = 1
        call WB.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER,1)
    End Sub
    document.write "<object id='WB' width='0' height='0' classid='CLSID:8856F961-340A-11D0-A96B-00C04FD705A2'></object>"
</script>

<object id="WebBrowser1" width="0" height="0" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"> </object>
<a href="#" onclick="Print()">Click Here to Print</a>
Community
  • 1
  • 1
Ruan Mendes
  • 90,375
  • 31
  • 153
  • 217