admin管理员组

文章数量:1389925

I'm trying to use jsPDF and html2canvas with es6.

I'm Importing html2canvas and jsPDF but getting an error on the addHTML when I ment out the addHTML the pdf is generated.

any clue what is the problem?

Thanks.

jspdf.debug.js:3754Uncaught Error: You need either or .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>

I'm trying to use jsPDF and html2canvas with es6.

I'm Importing html2canvas and jsPDF but getting an error on the addHTML when I ment out the addHTML the pdf is generated.

any clue what is the problem?

Thanks.

jspdf.debug.js:3754Uncaught Error: You need either https://github./niklasvh/html2canvas or https://github./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>

Share Improve this question asked Nov 20, 2016 at 19:30 user2428524user2428524 1081 gold badge2 silver badges9 bronze badges 1
  • Would like to know if you ever solved this problem. – TheNastyOne Commented Sep 14, 2017 at 22:44
Add a ment  | 

3 Answers 3

Reset to default 2

Include the following script in index.html instead of the import in typescript file

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

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

jsPDF requires html2canvas to be on the window:

window.html2canvas = html2canvas

Alternatively to calling window. you can also modify your import to this: import * as jsPDF from 'jspdf'

本文标签: javascriptUsing jsPDF and html2canvas with es6Stack Overflow