Last active
March 3, 2024 13:13
-
-
Save moaoa/89198dafc46c906c89fe898354cb2ee5 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
import jsPdf from 'jspdf'; | |
domToPng(ticketElement).then(dataUrl => { | |
const pdf = new jsPdf(); | |
const imgProps = pdf.getImageProperties(dataUrl); | |
const pdfWidth = pdf.internal.pageSize.getWidth(); | |
// const pdfHeight = pdf.internal.pageSize.getHeight(); | |
const imgWidth = (imgProps.width * (25.4 / 96)) | |
const imgHeight = (imgProps.height * (25.4/ 96)) | |
const x_axis = (pdfWidth * 0.5) - (imgWidth * 0.5) | |
const y_axis = 0 | |
pdf.addImage(dataUrl, 'PNG', x_axis, y_axis, imgWidth, imgHeight); | |
pdf.save('ticket.pdf'); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment