[英]Javascript printing function: Remove space from preview page
嗨,我正在使用HTML5和Javascript和jQuery 1.10开发Web应用程序。 我目前正在使用javascript打印功能。 在这一刻,打印预览看起来像这样(我在红色箭头下方描述):
我要实现的是正确格式化页面以使其在宽度和高度的100%处显示,换句话说,请删除尽可能多的空格(红色箭头)。
我的CSS代码:
@media print
{
* {-webkit-print-color-adjust:exact;}
.no-print, .no-print *
{
display: none !important;
}
.print {
position: fixed;
overflow: auto;
z-index: 100000; /* CSS doesn't support infinity */
/* Any other Print Properties */
}
}
JavaScript代码:
function exportaPDF(){
var mywindow = window.open('', 'CV', 'height=400,width=600');
mywindow.document.write('<html><head><title>Mi CV</title>');
mywindow.document.write('</head><body>');
mywindow.document.write($("body").html());
mywindow.document.write('</body></html>');
mywindow.document.close(); // necessary for IE >= 10
mywindow.focus(); // necessary for IE >= 10
mywindow.print();
mywindow.close();
return true;
}
注意,该网站有两列,但是使用CSS时,我在发送打印时隐藏了正确的部分。
我究竟做错了什么?
任何建议或帮助表示赞赏!
提前致谢
更新:解决方案
遵循@Jeroen Noten的建议,我解决了在打印以删除空间之前更改CSS属性的问题。 我刚刚添加了以下几行:
$("#ContenedorIzquierdo").css({
"width": "100%",
"margin-top": "0px"
});
请尝试以下操作:给要在打印中包括的部分提供一个ID(例如<div id="printedSection">
),然后引用该ID而不是整个正文,例如:
mywindow.document.write('<html><head><title>Mi CV</title>');
mywindow.document.write('</head><body>');
mywindow.document.write($("#printedSection").html()); // get only the printed section, not the full body
mywindow.document.write('</body></html>');
并确保在该部分中,内容的宽度没有限制。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.