【问题标题】:Saving current page as PDF with CSS styling使用 CSS 样式将当前页面保存为 PDF
【发布时间】:2017-03-24 09:44:26
【问题描述】:

我有这个简单的代码可以保存我当前的页面(基于我希望保存的 ID),但是当它打开保存窗口时,我将其视为没有样式的纯 HTML 代码。有没有办法保存 PDF,包括 CSS 中的所有样式?

<script>

function printDiv(divName) {

 var printContents = document.getElementById(divName).innerHTML;
 w=window.open();
 w.document.write(printContents);
 w.print();
 w.close();
}
</script>

【问题讨论】:

标签: javascript jquery html css pdf


【解决方案1】:
function printDiv(divName) {
var printContents = document.getElementById(divName).innerHTML;
w=window.open();
w.document.write('<style type="text/css"> /* your code here */ </style>' + printContents);
w.print();
w.close();
}

【讨论】:

    猜你喜欢
    • 2015-10-07
    • 1970-01-01
    • 2015-07-20
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    • 2019-08-04
    • 2014-04-13
    相关资源
    最近更新 更多