Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use addHTML function in jsPDF

Tags:

Could you please let me know how to use addHTML function in jsPDF libraries. Am trying to convert a webpage as pdf. want to use the addHTML function. Let me know what parameters need to be passed to get the entire webpage converted as pdf with header, logos, body etc

like image 264
Shireesh Avatar asked Jan 28 '15 13:01

Shireesh


1 Answers

First, you have to include jsPDF library, and also html2canvas or rasterizeHTML.

Then, just create a jsPDF object and save to pdf the entire 'body' tag (or whatever):

var pdf = new jsPDF('p','pt','a4');  pdf.addHTML(document.body,function() {      pdf.save('web.pdf');  });
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.js"></script>  <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.0.272/jspdf.debug.js"></script>    <body>      <p id="to-pdf">HTML content...</p>  </body>

You can find more examples on the jsPDF website: http://mrrio.github.io/jsPDF/

like image 50
gonzaloriestra Avatar answered Oct 02 '22 01:10

gonzaloriestra