Use JSPDF for Exporting Data HTML as PDF in 5 Easy Steps

by Faisal Shafi

JSPDF is the HTML5 client-side solution for generating PDFs. This is perfect for event tickets, reports, and certificates. Just include the JSPDF library in your <head>, generate your PDF using the many built-in functions.

You can use pdf from html as follows,

STEP 1. Download the Files From Github.

STEP 2. Add the Following Files in the Header

<em><span style="font-size:small;"><script type="text/javascript" src="jquery/jquery-1.7.1.min.js"></script> </span></em>
<em><span style="font-size: small;"><script type="text/javascript" src="jspdf.js"></script> </span></em>

<em><span style="font-size: small;"><script type="text/javascript" src="jspdf.plugin.standard_fonts_metrics.js"></script> </span></em>

<em><span style="font-size: small;"><script type="text/javascript" src="jspdf.plugin.split_text_to_size.js"></script> </span></em>

<em><span style="font-size: small;"><script type="text/javascript" src="jspdf.plugin.from_html.js"></script>

or just use link below:

<script src=”//mrrio.github.io/jsPDF/dist/jspdf.debug.js”></script>

STEP 3. Add JSPDF from HTML SCRIPT

<script>
function demoFromHTML() {
var doc = new jsPDF('p', 'in', 'letter');
var source = $('#testcase').first();
var specialElementHandlers = {
'#bypassme': function(element, renderer) {
return true;
}
};

doc.fromHTML(
source, // HTML string or DOM elem ref.
0.5, // x coord
0.5, // y coord
{
'width': 7.5, // max width of content on PDF
'elementHandlers': specialElementHandlers
});

doc.output('dataurl');
}
</script>

STEP 4. Add Your Body Content

<a href="javascript:demoFromHTML()" class="button">

<div id="testcase">

<h1>
We support special element handlers. Register them with jQuery-style.
</h1>

</div>

Browser Compatibility:

jsPDF will work in IE6+*, Firefox 3+, Chrome, Safari 3+, Opera. For IE9 and below.

4 thoughts on “Use JSPDF for Exporting Data HTML as PDF in 5 Easy Steps”

Leave a Reply to Ismael Cancel reply

Your email address will not be published. Required fields are marked *

Tools & Practices

Tools and Technologies we use at Applied

Contact us now

Popular Posts