How to save Basic HTML to PDF using jsPDF without save error

0

When I try to save a basic HTML to PDF using jsPDF, I get an error when trying to save. The error I get is "Unhandled exception at line 3648, column 11 in https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.debug.js 0x800a138f - JavaScript runtime error: Object expected".

What am I missing?

I tried adding FileSaver, but still received the error.

Here is my code:

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html" charset="utf-8" />
    <title>jsPDF</title>
    <!-- Include jQuery JavaScript -->
    <script type="text/javascript" src="../jquery/jquery-1.11.3.min.js"></script>
    <script type="text/javascript" src="../jquery/jquery-ui-1.10.4/ui/jquery-ui.js"></script>

    <script type="text/javascript" src="../FileSaver/FileSaver.min.js"></script>

    <!-- Include jsPDF JavaScript -->
    <!--<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.debug.js" integrity="sha384-NaWTHo/8YCBYJ59830LTz/P4aQZK1sS0SneOgAvhsIl3zBu8r9RevNg5lHCHAuQ/" crossorigin="anonymous"></script>-->
    <script src="https://unpkg.com/jspdf@latest/dist/jspdf.min.js"></script>
    <script type="text/javascript">

        function genPDF() {
            var doc = new jsPDF();
            doc.text(20, 20, 'TEST Message!!');
            doc.addPage();
            doc.text(20, 20, 'TEST Message Page 2!!');
            doc.save('TestDocument.pdf');
        }
    </script>
</head>
<body>

    <h1>jsPDF Demos</h1>
    <button onclick="genPDF();">Download PDF</button>

</body>
</html>

javascript
html
pdf
save
jspdf
asked on Stack Overflow Aug 5, 2020 by user6697669

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0