question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ES6 - how do you import either html2canvas or rasterizehtml?

See original GitHub issue

I’m using v 1.3.3 and jspdf.debug.js.

This is a mixin for vuejs, a simple function:

import html2canvas from 'html2canvas'
import jsPDF from 'jspdf'

PDF =
  methods:
    makePDF: () ->
      pdf = new jsPDF 'landscape', 'mm', 'a4'
      ele = document.querySelector '.roster-view'
      pdf.addHTML ele, () -> pdf.save 'roster.pdf'

export default PDF

I expected this to work, but:

jspdf.debug.js?ece2:4049 Uncaught Error: You need either https://github.com/niklasvh/html2canvas or https://github.com/cburgmer/rasterizeHTML.js at ...

What have I missed?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7

github_iconTop GitHub Comments

26reactions
AppSynergycommented, May 4, 2017

Got it, jspdf requires html2canvas to be attached to the window scope:

window.html2canvas = html2canvas
3reactions
stefanbollmanncommented, Sep 11, 2019

How can I set window.html2canvas = html2canvas in Angular?

I tried: .ts - File

import * as jsPDF from ‘jspdf’; import * as html2canvas from ‘html2canvas’;

export class ...... {

  downloadPDF2() {
      let pdf = new jsPDF();

      pdf.addHTML(document.getElementById('content'), 
        function save() {
          pdf.save('mypdf.pdf');
          window.open(pdf.output('bloburl'));
        } )
  }
Read more comments on GitHub >

github_iconTop Results From Across the Web

ES6 - how do you import either html2canvas or rasterizehtml ...
I 'm using v 1.3.3 and jspdf.debug.js. This is a mixin for vuejs, a simple function: import html2canvas from 'html2canvas' import jsPDF from ......
Read more >
Using jsPDF and html2canvas with es6 - Stack Overflow
I 'm Importing html2canvas and jsPDF but getting an error on the addHTML when I comment out the addHTML the pdf is generated....
Read more >
html2canvas - npm
Start using html2canvas in your project by running `npm i html2canvas`. There are 1794 other projects in the npm registry using html2canvas.
Read more >
Javascript – Using jsPDF and html2canvas with es6 - iTecNote
I 'm trying to use jsPDF and html2canvas with es6. I'm Importing html2canvas and jsPDF but getting an error on the addHTML when...
Read more >
Getting Started - html2canvas
You can install html2canvas through npm or download a built release. npm. npm install html2canvas. import html2canvas from ' ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found