Skip to content

Instantly share code, notes, and snippets.

@avtarnanrey
Last active January 21, 2025 16:09
Show Gist options
  • Save avtarnanrey/67888bbb6e56ba06382b3df648fb1195 to your computer and use it in GitHub Desktop.
Save avtarnanrey/67888bbb6e56ba06382b3df648fb1195 to your computer and use it in GitHub Desktop.
html2canvas or html-to-image or modern-screenshot with jsToPDF
download(): void {
const printContent = document.querySelector('.card-body');
if (printContent) {
// Replace below line with library function, whichever you're using.
domToPng(printContent, { quality: 1, scale: 2 }) // Scale set to 2 for better quality in PDF
.then((canvas) => {
const imgData = canvas;
const pdf = new jsPDF('p', 'mm', 'letter'); // Portrait, mm, Letter size
const imgWidth = 86;
const imgHeight = 54;
pdf.addImage(imgData, 'JPEG', 30, 30, imgWidth, imgHeight, undefined, 'NONE');
pdf.save(`membership-card-${this.member?.membershipNumber}.pdf`); // Download the PDF
})
.catch((error) => {
console.error('Error generating PDF', error);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment