admin管理员组

文章数量:1277383

I have web page with containing data I want that when I click generate pdf button it should create pdf of that page. And Save Locally .

I have searched alot but I am getting script to only create pdf by entering data is there any other way

Below is the method which I tried but it is not suitable I want to create whole page into pdf file.

jspdf

I also tried another code but it also does not create the file

  <script>


  function generatePDF(){} 

  var conv = new ActiveXObject("pdfServMachine.converter");
  conv.convert("", "c:\\google.pdf", false);
  WScript.Echo("finished conversion");
 }

 </script>
 <body onload="generatePDF()">
 </body>
 </html>

I have web page with containing data I want that when I click generate pdf button it should create pdf of that page. And Save Locally .

I have searched alot but I am getting script to only create pdf by entering data is there any other way

Below is the method which I tried but it is not suitable I want to create whole page into pdf file.

jspdf.

I also tried another code but it also does not create the file

  <script>


  function generatePDF(){} 

  var conv = new ActiveXObject("pdfServMachine.converter");
  conv.convert("http://www.google.", "c:\\google.pdf", false);
  WScript.Echo("finished conversion");
 }

 </script>
 <body onload="generatePDF()">
 </body>
 </html>
Share Improve this question edited Nov 3, 2013 at 20:36 BenMorel 36.6k51 gold badges205 silver badges336 bronze badges asked Nov 19, 2012 at 6:15 user1808433user1808433 3,4054 gold badges18 silver badges17 bronze badges 8
  • stackoverflow./questions/1686280/… – Akhilraj N S Commented Nov 19, 2012 at 6:18
  • if this is a direct copy from your code than you need to write the word function correctly – Eyal Alsheich Commented Nov 19, 2012 at 6:19
  • @EyalAsheich yes i have made it write but nothing happens – user1808433 Commented Nov 19, 2012 at 6:21
  • 2 Have you tried printing the page?? – Steve Robinson Commented Nov 19, 2012 at 6:22
  • @AkhilrajNS the link you provides is fine can you help me overhere to add that code and where is the file saved – user1808433 Commented Nov 19, 2012 at 6:22
 |  Show 3 more ments

2 Answers 2

Reset to default 3

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

I am a bit late but let me tell you that, the code you are using is only patible with old versions of Microsoft browser(i.e) because it contains WScript & ActiveX Component.

Yes, you can generate it with jsPDF.js. Just search this javascript file in google and download it locally then include it like shown 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>

本文标签: javascripthow to convert a web page into pdf by button click in html5Stack Overflow