<script>
function pdfToHTML(){ $.ajaxSetup({cache: true}); $.getScript("https://unpkg.com/jspdf@latest/dist/jspdf.min.js"); $.ajaxSetup({cache: false}); this.one("click", function () { // pdfToHTML() }); $('#blogArticle pre code').each(function(i, block) { hljs.highlightBlock(block); }); var pdf = new jsPDF('p', 'pt', 'letter'); source = $('#blogArticle')[0]; specialElementHandlers = { '#bypassme': function(element, renderer){ return true } }; margins = { top: 50, left: 60, width: 545 }; pdf.fromHTML( source // HTML string or DOM elem ref. , margins.left // x coord , margins.top // y coord , { 'width': margins.width // max width of content on PDF , 'elementHandlers': specialElementHandlers }, function (dispose) { // dispose: object with X, Y of the last line add to the PDF // this allow the insertion of new lines after html pdf.save('html2pdf.pdf'); } ) }
</script>