如何使用php打印出网页的某些部分

how to take print out of some part of webpage using php?

本文关键字:些部 网页 何使用 php 打印      更新时间:2023-09-26

我想把打印出来的网页。我已经为这个和这个工作写了代码。代码是:

function printPage(){
        var tableData = '<table border="1">'+document.getElementsByTagName('table')[0].innerHTML+'</table>';
        var data = '<button onclick="window.print()">Print this page</button><br/>'+tableData;       
        myWindow=window.open('','','width=500,height=600');
        myWindow.innerWidth = screen.width;
        myWindow.innerHeight = screen.height;
        myWindow.screenX = 0;
        myWindow.screenY = 0;
        myWindow.document.write(data);
        myWindow.focus();
    };

但是我不想让'Print this page'按钮打印出来。

你可以使用@media css style方法:

@media print {
/* css here to take out the "print this */
}

这只会在你打印时应用css样式。

例如,你可以给你的按钮一个类,比如class="printbtn"

:

@media print {
    .printbtn { display: none; }
}

直接使用css打印定义区域....

 <style type="text/css">
    #printit { display: block; }
    @media print
    {
        #dont-printit { display: none; }
        #printit { display: block; }
    }
    </style>

并使用<div id="printit">打印网页区域的一部分......