使用jsPDF和html2canvas与ES6

问题描述 投票:3回答:3

我试图用jsPDF和html2canvas与ES6。

我导入html2canvas和jsPDF但对addHTML得到一个错误,当我注释掉生成PDF格式的addHTML。

任何线索是什么问题?

谢谢。

jspdf.debug.js:3754Uncaught错误:您需要用https://github.com/niklasvh/html2canvashttps://github.com/cburgmer/rasterizeHTML.js(...)jsPDFAPI.addHTML @ jspdf.debug.js:@ index.js 3754(匿名函数):@ bundle.js 12(匿名函数)V1。 27.2:31546(匿名函数)@ bundle.js V1.27.2:31547__webpack_require__ @引导f7845b2 ...:555fn @引导f7845b2 ...:86(匿名函数)@引导f7845b2 ...:578__webpack_require__ @引导f7845b2 ...:555(匿名函数)@引导f7845b2 ...:578(匿名函数)@引导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>
javascript node.js reactjs jspdf html2canvas
3个回答
0
投票

https://github.com/MrRio/jsPDF/issues/1225

jsPDF要求html2canvas是窗口:

window.html2canvas = html2canvas


0
投票

或者调用window.你还可以修改导入到这一点:import * as jsPDF from 'jspdf'


0
投票

包括下面的脚本中的index.html,而不是在打字稿文件导入

<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.js"></script>

© www.soinside.com 2019 - 2024. All rights reserved.