-
-
Save gbili/5f422471042775be527f0ea3b5f4af92 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function print() { | |
const filename = 'ThisIsYourPDFFilename.pdf'; | |
html2canvas(document.querySelector('#nodeToRenderAsPDF')).then(canvas => { | |
let pdf = new jsPDF('p', 'mm', 'a4'); | |
pdf.addImage(canvas.toDataURL('image/png'), 'PNG', 0, 0, 211, 298); | |
pdf.save(filename); | |
}); | |
} | |
// Variant | |
// This one lets you improve the PDF sharpness by scaling up the HTML node tree to render as an image before getting pasted on the PDF. | |
function print(quality = 1) { | |
const filename = 'ThisIsYourPDFFilename.pdf'; | |
html2canvas(document.querySelector('#nodeToRenderAsPDF'), | |
{scale: quality} | |
).then(canvas => { | |
let pdf = new jsPDF('p', 'mm', 'a4'); | |
pdf.addImage(canvas.toDataURL('image/png'), 'PNG', 0, 0, 211, 298); | |
pdf.save(filename); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment