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?
Found out what the issue was. The saveAs function is part of FileSaver.js so I just needed to include this and everything worked.
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.
You can also use jspdf.debug.js it contains all of the plugins in one file. This way you are covered if something else is needed.
-Cheers
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Hello world</title>
</head>
<body>
<h1>Hello world</h1>
<script type="text/javascript" src="jspdf.min.js"></script>
<script type="text/javascript">
var pdf = new jsPDF();
pdf.text(30, 30, 'Hello world!');
pdf.save('hello_world.pdf');
</script>
</body>
</html>
来源:https://stackoverflow.com/questions/20340194/doc-save-throwing-error-with-jspdf