How to convert web page to pdf by clicking a button in html5

I have a data web page that I want so that when I click the Create PDF button, it should create a pdf page for this page. And save locally.

I searched alot, but I only get a pdf creation script by entering data, is there any other way

Below is the method I tried, but it does not work. I want to create a whole page in a pdf file.

jspdf.com

I also tried different code, but it also does not create the file

<script> function generatePDF(){} var conv = new ActiveXObject("pdfServMachine.converter"); conv.convert("http://www.google.com", "c:\\google.pdf", false); WScript.Echo("finished conversion"); } </script> <body onload="generatePDF()"> </body> </html> 
+6
source share
2 answers

You did not declare the function correctly. It should be generatePDF(){ instead of generatePDF(){} . Your } should only be at the end of the function.

+3
source

I'm a little late, but let me tell you that the code you use is only compatible with older versions of the Microsoft browser (ie), because it contains WScript and the ActiveX component.

Yes, you can generate it using jsPDF.js . Just find this javascript file in google and upload it locally, then enable it as below.

 <script src="~/js/jspdf.js"></script> <script> var doc = new jsPDF('p', 'pt', 'letter'); var specialElementHandlers = { '#editor': function (element, renderer) { return true; } }; $('#btn_Pdfprint').click(function () { doc.fromHTML($('#myTabContent').html(), 25, 25, { 'width': 790, 'elementHandlers': specialElementHandlers }); doc.save('mywebpagee.pdf'); window.location.reload(); }); </script> 
0
source

All Articles