This simple web is for testing jspdf.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title> creando pdfs</title>
<link rel="stylesheet" href="">
<script src="js/jspdf.js"></script>
<script src="js/FileSaver.js"></script>
</head>
<body>
<h1> creando un pdf</h1>
<script>
function creapdf(){
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');
}
</script>
<a href="javascript:creapdf()">Download PDF</a>
</body>
</html>
It returns an error. saveAs
is not defined.
I have seen this answer which seems to fix the problem https://stackoverflow.com/questions/20340194/doc-save-throwing-error-with-jspdf
However, although I have linked the libraries
<script src="js/jspdf.js"></script>
<script src="js/FileSaver.js"></script>
it keeps giving me the error.
I think I know what's going on. Copy the file
jspdf.min.js
inside the folderdist
. then you add itand it should work.
Delete
<script src="js/FileSaver.js"></script>
, you don't need it with the browser version you are using.It didn't work for you because the file
jspdf.js
you were using was not the final file. In general, when you download one of these libraries, use the files found in the dist folder, which by convention has the final files in their minified and debug versions.