0

So I've been working on trying to convert an HTML file produced to a PDF. I have been looking at JSPDF and come up with the following code but when I hit submit nothing happens, I can see no error in my browser debug.

        <!DOCTYPE html>  <html lang="en"><head>

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.2.61/jspdf.min.js"></script>
    <script>
    var doc = new jsPDF(); 
    var specialElementHandlers = { 
        '#editor': function (element, renderer) { 
            return true; 
        } 
    };
    $('#submit').click(function () { 
        doc.fromHTML($('#content').html(), 15, 15, { 
            'width': 522, 
                'elementHandlers': specialElementHandlers 
        }); 
        doc.save('Logbook Summary.pdf'); 
    });

    </script>

    <div id="content"> 

     <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><title>Logbook Summary</title>    

    </head> 
Test text here

</div> <div id="page"></div>

<button id="submit">Export to  PDF</button>

 </html> 

Any help would be appreciated, I am sure I am missing something simple here.

Medberry
  • 23
  • 1
  • 7
  • please check your header section,`
    Logbook Summary Test text here
    – Codeone Jun 13 '16 at 12:35
  • Sorry in what way? I've removed the actual text that I Want to print, it is inside the content div. When I hit the button nothing at all happens. – Medberry Jun 13 '16 at 12:43

1 Answers1

0

Sorted

This is because I defined my "doc" variable outside of my click event.

Sorted it from this thread:

Export HTML page to PDF on user click using JavaScript

Community
  • 1
  • 1
Medberry
  • 23
  • 1
  • 7