(1) Need: is open a PDF file on the Web page, and then directly open the printer, direct printing, without the user to click the Print button again, so that the user experience good
(2) Experience:
I find the information on the Internet is to use Window.print (), but this is just print the contents of the label, the content of the URL of the PDF is not printed, I heard that there are plug-ins on the Internet pdf.js and so on.
Feel also no use, at last I do not know how to do, got a long time to know someone with IFrame loading PDF and then print so reference to really can print, suddenly feel great God in the lights dim place!
(3) Main code:
Tag IFRAME Code
<iframe style= "Display:none" id= "Printiframe" src= "<%=data%>" ></iframe>
JavaScript code, very simple, actually I simplified a lot of
<script type= "Text/javascript" > $ (document). Ready (function () { doprint ();}); /Click the Print button to trigger the event "function Doprint () { $ (" #printIframe ") [0].contentwindow.print ();} </script>
<%=data%> is the path of my PDF, which is less than 10 lines of code can solve the problem I have been looking for a long time, so I hope to share to you confused you
(4) Effect:
JS Direct print PDF file content