[英]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.