在es6中使用jsPDF和html2canvas [英] Using jsPDF and html2canvas with es6
问题描述
我正在尝试将jsPDF和html2canvas与es6结合使用.
I'm trying to use jsPDF and html2canvas with es6.
我正在导入html2canvas和jsPDF,但是在addHTML上出现错误 当我注释掉addHTML时,会生成pdf.
I'm Importing html2canvas and jsPDF but getting an error on the addHTML when I comment out the addHTML the pdf is generated.
任何提示是什么问题?
谢谢.
jspdf.debug.js:3754未捕获的错误:您需要 https://github.com/niklasvh/html2canvas 或 https://github.com/cburgmer/rasterizeHTML.js (… )jsPDFAPI.addHTML @ jspdf.debug.js:3754(匿名函数)@ index.js:12(匿名函数)@ bundle.js?V1.27.2:31546(匿名函数)@ bundle.js?V1.27.2:31547__webpack_require__ @ bootstrap f7845b2…:555fn @ bootstrap f7845b2…:86(匿名函数)@ bootstrap f7845b2…:578__webpack_require__ @ bootstrap f7845b2…:555(匿名函数)@ bootstrap f7845b2…:578(匿名函数)@ bootstrap f7845b2…:578 >
jspdf.debug.js:3754Uncaught Error: You need either https://github.com/niklasvh/html2canvas or https://github.com/cburgmer/rasterizeHTML.js(…)jsPDFAPI.addHTML @ jspdf.debug.js:3754(anonymous function) @ index.js:12(anonymous function) @ bundle.js?V1.27.2:31546(anonymous function) @ bundle.js?V1.27.2:31547__webpack_require__ @ bootstrap f7845b2…:555fn @ bootstrap f7845b2…:86(anonymous function) @ bootstrap f7845b2…:578__webpack_require__ @ bootstrap f7845b2…:555(anonymous function) @ bootstrap f7845b2…:578(anonymous function) @ bootstrap f7845b2…:578
import html2canvas from 'html2canvas';
import jsPDF from 'jspdf';
doc.setFontSize(40);
doc.text(35, 25, "Paranyan loves jsPDF");
doc.addHTML(document.footer,function() {
pdf.save('web.pdf');
});
<footer>
<p id="to-pdf">HTML content...</p>
</footer>
推荐答案
在index.html中包括以下脚本,而不是在打字稿文件中导入
Include the following script in index.html instead of the import in typescript file
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.js"></script>
这篇关于在es6中使用jsPDF和html2canvas的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!