Main content of this article:
If you use the print button that comes with the browser, you cannot perform other printing-related operations, such as passing the number of prints, etc. Therefore, you need to retain and assign the function of printing to the buttons you added, so that you can trigger custom functions while clicking the button.
The code copy is as follows:
<input type="button" id="btnPrint" value="Print" />
<iframe frameborder=0 id="printPDFIframe" src=""<span style="white-space:pre"> </span>></iframe>
The code copy is as follows:
<script type="text/javascript">
$("#btnPrint").click(function(){
<pre code_snippet_id="248441" snippet_file_name="blog_20140321_2_4849863" name="code"><span style="white-space:pre"> </span>printPDF ();</pre> }); function printPDF(){ if (navigator.appName == 'Microsoft Internet Explorer'){ //Wait until PDF is ready to print if(typeof document.getElementById("printPDFIframe") .print == 'undefined'){ setTimeout(function(){printPDF ("printPDFIframe");},
1000); }else{ var x = document.getElementById("printPDFIframe"); x.print(); } }else{ PDFIframeLoad(); // for chrome } } // for Chrome has cancel/confirm , Cannot send directly to printer function PDFIframeLoad() { debugger; var iframe = document.getElementById("printPDFIframe"); if(iframe.src)
{ var frm = iframe.contentWindow; frm.focus();// focus on contentWindow is needed on some ie versions frm.print(); return false; } }</script>
<pre></pre>
<pre></pre>