[英]how to remove header and footer into the window.print();
I am using window.print() for printing page, but I got header and footer contains page title, file path, page number, and date.我正在使用 window.print() 打印页面,但我得到的页眉和页脚包含页面标题、文件路径、页码和日期。 How to remove them or edit?
如何删除它们或编辑?
I tried this also.我也试过这个。
@media print {
@page { margin: 0; }
body { margin: 1.6cm; }
}
i try all solution of this page but any solution is not working for me. 我尝试了此页面的所有解决方案,但任何解决方案都不适合我。
this is my div content that is find from POJO.这是从 POJO 中找到的我的 div 内容。
<div id="textDiv">
<pre id="foo"><%= student.getDescription()%></pre>
</div>
this is my button.这是我的按钮。
<button onclick="printDiv('textDiv')">Print PDF</button>
this is my Script for Print.这是我的打印脚本。
function printDiv(divName) {
var printContents = document.getElementById(divName).innerHTML;
var originalContents = document.body.innerHTML;
document.body.innerHTML = printContents;
window.print();
document.body.innerHTML = originalContents;
}
// Use this method
@media print {
.footer,
#non-printable {
display: none !important;
}
#printable {
display: block;
}
}
Try this below试试下面这个
<script language="javascript">
function printDiv() {
var printContents = document.getElementById("divName").innerHTML;
var originalContents = document.body.innerHTML;
document.getElementById('header').style.display = 'none';
document.getElementById('footer').style.display = 'none';
document.body.innerHTML = printContents;
window.print();
document.body.innerHTML = originalContents;
}
</script>
The content div to be visible to print would be named below打印可见的内容 div 将在下面命名
<div id="divName">Print Content</div>
Then on the print button, you do the below然后在打印按钮上,执行以下操作
<button onClick="printDiv();">Print</button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.