Skip to content

React js: addImage is not a function #2184

@longtd269

Description

@longtd269

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions