Reputation: 159
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?
Upvotes: 14
Views: 30471
Reputation:
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.
Upvotes: 10
Reputation: 6741
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.
Upvotes: 1
Reputation: 6156
It is possible indeed with pdf.js
plugin
pdf.js
is an HTML5 experiment that explores building a faithful and efficient PDF renderer without native code assistance.
Upvotes: -6
Reputation: 1479
You need to use any pdf generating library. You have not specified in which technology you are working (Php, .net or anything else)
In PHP you can use tcpdf library, Where you can pass html to generate pdf
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->AddPage();
$pdf->writeHTML($pdfHtml, true, false, true, false, '');
Where $pdfHtml will be your page html
In your case when clicking on 'save as pdf' button you can get html by using html() method of jquery
eg.
var pageHtml = $('html').html();
by passing pageHtml to ajax page, You can create pdf in ajax page
Upvotes: -2