-
-
Save Fahrek/fc3b069cb3e303d3ce843b8c3c74cb3e 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