Is it possible to save HTML page as PDF using JavaScript or jquery?
In Detail:
I generated one HTML Page which contains a table . It has one button 'save as PDF'. If user clicks that button then that HTML page has to convert as PDF file.
Is it possible using JavaScript or jquery?
Generate PDF using JavaScript The following example shows how to use the jsPDF library to generate PDF file using JavaScript. Specify the content in text() method of jsPDF object. Use the addPage() method to add new page to PDF. Use the save() method to generate and download PDF file.
Explanation: The Export Button has been assigned a jQuery click event handler. When the Export Button is clicked, the HTML Table is converted into a HTML5 Canvas using html2canvas plugin and then the HTML5 Canvas will be exported to PDF using the pdfmake plugin.
Yes, Use jspdf To create a pdf file.
You can then turn it into a data URI and inject a download link into the DOM
You will however need to write the HTML to pdf conversion yourself.
Just use printer friendly versions of your page and let the user choose how he wants to print the page.
Edit: Apparently it has minimal support
So the answer is write your own PDF writer or get a existing PDF writer to do it for you (on the server).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With