Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

doc.save() throwing error with jspdf

When I try and use the save() function for jsPDF it's throwing the following error:

ReferenceError: saveAs is not defined

I'm just trying a very simple example:

var doc = new jsPDF();
doc.text(20, 20, 'Hello world!');
doc.text(20, 30, 'This is client-side Javascript, pumping out a PDF.');
doc.addPage();
doc.text(20, 20, 'Do you like that?');

doc.save('test.pdf');

Anyone have any ideas what's wrong?

like image 930
Owen Davey Avatar asked Dec 02 '13 23:12

Owen Davey


2 Answers

Found out what the issue was. The saveAs function is part of FileSaver.js so I just needed to include this and everything worked.

like image 152
Owen Davey Avatar answered Nov 17 '22 14:11

Owen Davey


I don't have enough to comment yet, so I'm adding this as an answer... saveAs() is a w3c interface. If adding FileSaver fixed your issue, that means you were using an old browser; FileSaver.js is used as a shim for jsPDF to support older browsers that don't have that function natively.

like image 35
Kyle Baker Avatar answered Nov 17 '22 14:11

Kyle Baker