3

I wish to print a PDF at client side when a user clicks a particular link. However, the PDF should not open and print should be fired. It may not be silent printing, a OS popup asking the printer to use can come. My PDF Reader shall be Adobe Reader. I found a lot of links to try to however found they are dependent on Browser being used. I tried this code piece to successfully print in Chrome but i think chrome has its own PDF Renderer.

<script>function iprint(ptarget){
        ptarget.focus();
        ptarget.print();
         } 
</script><body>
<iframe name="theiframe" id="theiframe" width="500" height="200" src="http://192.168.108.105:8081/PDfTest/Excel.pdf" style="display:none">
</iframe>
     <input type="button" value="print iframe" onclick="iprint(theiframe);" />
</body> 

Also tried this code piece , but this opens the PDF and then prints:

<html>
<script language="javascript">
timerID = setTimeout("exPDF.print();", 1000);
</script>
<body>
<object id="exPDF" type="application/pdf" data="111.pdf" width="100%" height="500"/>
</body>
</html>

Would appreciate any help.

Abhishek
  • 1,031
  • 4
  • 16
  • 25

1 Answers1

0

Are you okay with opening the PDF, but in a way that is invisible to the user? If so, you could set visibility of the object tag with something like <object style="display: none;" .... This way the PDF has a chance to open (unbeknownst to the user) and then seemingly magically print the pdf.

Hope this helps!