Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to export a html page to pdf in client side using JavaScript or jQuery?

And if it is not possible then what are the other alternatives?

I tried to convert a complete html page to pdf with dynamic values but I can't .

But I saw some API like jspdf but it is not useful for me.

Is it possible to save a HTML page as PDF file using JavaScript or jQuery?

In Detail:

I generated one HTML Page which contains a list grid which populated all the available reports dynamically. It has one button 'save as PDF'. If the user clicks this button then the HTML page will be converted to a PDF file.

Is it possible using JavaScript or jquery?

like image 465
sid Avatar asked Aug 27 '13 07:08

sid


People also ask

How do I export my HTML page as PDF using JavaScript?

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.

How can download HTML page as PDF using jQuery?

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.

How do I save a PDF in JavaScript?

To save HTML page as PDF using JavaScript, we can use the html2pdf library. const element = document. getElementById("element-to-print"); const opt = { margin: 1, filename: "myfile.


2 Answers

jsPDF has a HTML renderer but it is in the early stages:

https://github.com/mrrio/jsPDF

http://parall.ax/products/jspdf

Another solution might be https://github.com/eKoopmans/html2pdf.js

But the best solution is the one from mujaffars. User AJAX and a stable PDF library written in PHP like FPDF, PDFLib, TCPDF and others.

like image 69
Daniel Ruf Avatar answered Oct 02 '22 14:10

Daniel Ruf


Well, if I have got your question properly then u need to Export a Table Data as PDF?

If Yes, then please see datatables.js with simple example here.

Also, look into use BytescoutPDF.js (Bytescout PDF Generator for JavaScript) to draw PDF invoice and JSPDF you can get the details here.

like image 25
Shubh Avatar answered Sep 29 '22 14:09

Shubh