4

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 comment out the addHTML the pdf is generated.

any clue what is the problem?

Thanks.

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>

1
  • Would like to know if you ever solved this problem. Commented Sep 14, 2017 at 22:44

3 Answers 3

2

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>

Sign up to request clarification or add additional context in comments.

Comments

1

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

jsPDF requires html2canvas to be on the window:

window.html2canvas = html2canvas

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.