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
<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">Run Code</a> <div id="testcase"> <h1> We support special element handlers. Register them with jQuery-style. </h1> </div>
STEP 5. 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(
$('#testcase').get(0),
0.5, // x coord
0.5, // y coord
{
'width': 7.5, // max width of content on PDF
'elementHandlers': specialElementHandlers
});
doc.output('dataurl');
}
</script>
Browser Compatibility:
jsPDF will work in IE6+*, Firefox 3+, Chrome, Safari 3+, Opera. For IE9 and below.
To learn more about
Contact Us
Whats the diference between, step 3 and step 5? Seems quite the same to me…
good question !
i even wonder
Make sure you wrap your script tags with font-size, people!