Last active
January 21, 2025 16:09
-
-
Save avtarnanrey/67888bbb6e56ba06382b3df648fb1195 to your computer and use it in GitHub Desktop.
html2canvas or html-to-image or modern-screenshot with jsToPDF
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
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