HTA/IE11 中的 jsPDF + html2canvas
jsPDF + html2canvas in HTA/IE11
我想从 hta 文件 (http-equiv="x-ua-compatible" content="ie=11") 生成 PDF。 Append to child 就像一个魅力。但是它不适用于 jsPDF...感谢任何帮助!
包含的脚本:
<script src="polyfill.min.js"></script><!-- https://cdn.jsdelivr.net/npm/promise-polyfill@7/dist/polyfill.min.js -->
<script src="jspdf.js"></script><!-- https://github.com/MrRio/jsPDF/blob/master/src/jspdf.js -->
<script src="html2canvas.js"></script><!-- https://html2canvas.hertzen.com/dist/html2canvas.js -->
DIV 打印:
<div class ="print" id="print">
<h3>print!</h3>
<input type="button" id="pdfPrint" value="PDF erstellen" />
</div>
脚本代码:
document.getElementById('pdfPrint').addEventListener('click', function() {
html2canvas(document.getElementById("print")).then(function(canvas) {
// document.getElementById("print").appendChild(canvas);
var img = canvas.toDataURL("image/jpeg", 1.0);
var pdf = new jsPDF();
pdf.addImage(img,'JPEG',20,20);
pdf.save('Testung.pdf');
}
});
});
我已经用你的代码做了测试。而且我发现在IE11中会有ReferenceError: 'jsPDF' is undefined。
重点是jsPDF的引用。您应该用最新的替换您的 jsPDF 脚本:https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.4/jspdf.min.js
那么运行结果如下图所示:
我想从 hta 文件 (http-equiv="x-ua-compatible" content="ie=11") 生成 PDF。 Append to child 就像一个魅力。但是它不适用于 jsPDF...感谢任何帮助!
包含的脚本:
<script src="polyfill.min.js"></script><!-- https://cdn.jsdelivr.net/npm/promise-polyfill@7/dist/polyfill.min.js -->
<script src="jspdf.js"></script><!-- https://github.com/MrRio/jsPDF/blob/master/src/jspdf.js -->
<script src="html2canvas.js"></script><!-- https://html2canvas.hertzen.com/dist/html2canvas.js -->
DIV 打印:
<div class ="print" id="print">
<h3>print!</h3>
<input type="button" id="pdfPrint" value="PDF erstellen" />
</div>
脚本代码:
document.getElementById('pdfPrint').addEventListener('click', function() {
html2canvas(document.getElementById("print")).then(function(canvas) {
// document.getElementById("print").appendChild(canvas);
var img = canvas.toDataURL("image/jpeg", 1.0);
var pdf = new jsPDF();
pdf.addImage(img,'JPEG',20,20);
pdf.save('Testung.pdf');
}
});
});
我已经用你的代码做了测试。而且我发现在IE11中会有ReferenceError: 'jsPDF' is undefined。
重点是jsPDF的引用。您应该用最新的替换您的 jsPDF 脚本:https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.4/jspdf.min.js
那么运行结果如下图所示: