error creating a pdf with jspdf

0

This simple web is to test 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 that seems to solve the problem link

However, although I have lincada the libraries

<script src="js/jspdf.js"></script>
<script src="js/FileSaver.js"></script>

continues to return the error.

    
asked by kamome 28.02.2016 в 21:40
source

1 answer

2

I think I know what happens. Copy the jspdf.min.js file that is inside the dist folder. Then you add it

<script src="js/jspdf.min.js"></script>

and it should work.

Delete <script src="js/FileSaver.js"></script> , you do not need it with the version of browsers that you are using.

It did not work for you because the jspdf.js file you were using was not the final file. In general, when you download one of these libraries, use the files that are in the dist folder, which by convention has the final files in their minified and debug versions.

    
answered by 28.02.2016 / 22:16
source