softcode
softcode

Reputation: 4668

Basic jsPDF Implementation

Using jsPDF, currently attempting to do the following:

  1. Define downloadPDF function

    • Generate PDF document with "Hello world" string
    • Download PDF document
  2. Declare a button with an onclick that calls downloadPDF()

<html>

<head>
  <title>Page Title</title>
  <script type="text/javascript" src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
  <script src="//mrrio.github.io/jsPDF/dist/jspdf.debug.js"></script>
</head>

<body>
  <script>
    function downloadPDF() {
      var doc = new jsPDF('p', 'in', 'letter');
      doc.text('Hello world', 10, 10);
      doc.save('myPDF');
    }
  </script>
  <button onclick="downloadPDF()" class="button">Run Code</button>
</body>

</html>

But the PDF document turns out to be empty.

Any ideas ?

Upvotes: 0

Views: 1869

Answers (1)

Alfredo Delgado
Alfredo Delgado

Reputation: 689

What are the arguments that you're passing to the jsPDF constructor supposed to do? Removing them worked for me:

var doc = new jsPDF();

Working example: http://output.jsbin.com/kaxafuwiri

Upvotes: 2

Related Questions