js實現網頁pdf打印


代碼如下:

function PdfPrintDiv() {
    //隱藏不想打印的部分
    document.getElementById("ubtn").style.display="none"; 
    //實現打印
    bdhtml = window.document.body.innerHTML;
    sprnstr = "<!--startprint-->";
    eprnstr = "<!--endprint-->";
    prnhtml = bdhtml.substr(bdhtml.indexOf(sprnstr) + 17);
    prnhtml = prnhtml.substring(0, prnhtml.indexOf(eprnstr));
    window.document.body.innerhtml = prnhtml;
    window.print();
    //完成后不隱藏
    document.getElementById("ubtn").style.display="block";
}
</script>

在button或者要觸發的元素/事件實現創建id"ubtn",調用該PdfPrintDiv()方法,同時,自行實現那些葯隱藏。完成打印后顯示即可。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM