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.

React js: addImage is not a function

See original GitHub issue

I’m using jsPDF for react project. I have error: addImage is not a function jsPDF version: “jspdf”: “^1.4.1”

This is mycode: import * as jsPDF from ‘jspdf’

html2canvas(input, {useCORS: true})
      .then((canvas) => {
        const imgData = canvas.toDataURL('image/png');
        let imgWidth = 210;
        let pageHeight = 297;
        let imgHeight = canvas.height * imgWidth / canvas.width;
        let heightLeft = imgHeight;
        let doc = new jsPDF('p', 'mm', 'a4');
        let position = 0;
        doc.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight);
        heightLeft -= pageHeight;
        while (heightLeft >= 0) {
          position = heightLeft - imgHeight;
          doc.addPage();
          doc.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight);
          heightLeft -= pageHeight;
        }
        doc.save("test.pdf");
      })  ;

Did i do something wrong?

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
zackshencommented, Dec 24, 2018

@longtd269 i met this problem just now. it’s a duplicate bug, you should lock your jspdf version now, like “~1.4.1”

0reactions
Uzlopakcommented, Dec 27, 2018

Version 1.5.3 got released and fixes the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React js: addImage is not a function · Issue #2184 - GitHub
I'm using jsPDF for react project. I have error: addImage is not a function jsPDF version: "jspdf": "^1.4.1" This is mycode: import *...
Read more >
addImage error (Cannot read property ... - Stack Overflow
Everything seems to work OK, I can create, save the pdf, position the text, I can call the function "backgroundimage" (tested it with...
Read more >
Images - React Native
React Native provides a unified way of managing images and other media assets in your Android and iOS apps. To add a static...
Read more >
Require Image Not Working in ReactJS - YouTube
Learn how to add image in react js or add image in react js. React image is used with simple img tag in...
Read more >
JsPDF addimage is not a function - Yo Motherboard
There appears to be a bug with the older version of this framework for some people. If you have downloaded the latest version...
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