我有这个简单的代码可以保存我的当前页面(基于我希望保存的 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>
最佳答案
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();
}
关于javascript - 使用 CSS 样式将当前页面保存为 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42996064/