Question

I have a client that can not use jQuery for any reason, is jsPDF dependent on jQuery or is there a way to specify use pure javascript?

Was it helpful?

Solution

The latest version of jsPDF has removed the dependence on jQuery, the version I used is v1.5.3. You can view the demo on CodePen:

CodePen Demo

<!-- load only jsPDF -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.min.js"></script>
// Use it now!
var doc = new jsPDF();
var specialElementHandlers = {
    '#editor': function (element, renderer) {
        return true;
    }
};

var cmd = document.querySelector('#cmd');
cmd.addEventListener("click", function () {   
    var contentContainer = document.querySelector('#content');
    doc.fromHTML(contentContainer.outerHTML, 15, 15, {
        'width': 70,
        'elementHandlers': specialElementHandlers
    });
    doc.save('sample-file.pdf');
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top