1. 程式人生 > >web生成pdf後的直接列印,隱藏iframe

web生成pdf後的直接列印,隱藏iframe

頁面  <iframe id="iPrint" style='height:0; width:0;' ></iframe>

<input type="button" value="Print" onclick="PrintPdf()"/>

<script type="text/javascript">

function PrintPdf() {

           if (document.getElementById("iPrint").attachEvent) {

                document.getElementById("iPrint").attachEvent("onload", function () { document.getElementById("iPrint").focus(); document.getElementById("iPrint").contentWindow.print(); });


            } else {
                document.getElementById("iPrint").onload = function () {
                    document.getElementById("iPrint").focus(); document.getElementById("iPrint").contentWindow.print();
                }
            }

            document.getElementById("iPrint").src = "./invSa.aspx?action=toPdf";

}

</script>

table模板aspx生成pdf可參考

http://blog.csdn.net/luan729/article/details/51818914

vs2010 asp.net  

例項下載地址:http://218.95.37.10:8085/Html2pdf.rar