I have a very simple implementation of jsPDF in a react project I'm currently working on. Just trying to run the sample 'hello world' code but the save method throws the following error:
My code is very simple, first, import the lib like this:
import jsPDF from 'jspdf';
Then on a click event function from a Component
<IOControls exportDrawing={this.exportDrawing} />
I run:
exportDrawing() {
const doc = new jsPDF();
doc.text('Hello World!', 10, 10);
console.log(doc); // shows an object
doc.save('a4.pdf');
}
The above error triggers on save() but I have no idea what exactly is causing it.
Any help will be much appreciated.
UPDATE I just noticed that if I call the methods at the root of my app component the code works fine, the problem ocurrs when it is called from within other components.
Here is my setup
<App>
<Sketch>
<SketchControls>
<IOControls>
exportDrawing() is declared in <Sketch> and the its triggered from a button in <IOControls>
from Getting TypeError Arg 1 when calling save method of jsPDF

No comments:
Post a Comment