fixed error - building image
This commit is contained in:
parent
0dac797e21
commit
04806c6d53
@ -68,38 +68,7 @@ const Invoice = ({ invoiceData, currencySymbol }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const downloadPDF = async () => {
|
const downloadPDF = async () => {
|
||||||
setIsGenerating(true);
|
alert("Under the woking");
|
||||||
|
|
||||||
try {
|
|
||||||
const invoice = invoiceRef.current;
|
|
||||||
const canvas = await html2canvas(invoice, {
|
|
||||||
scale: 2,
|
|
||||||
useCORS: true,
|
|
||||||
logging: false,
|
|
||||||
backgroundColor: "#ffffff",
|
|
||||||
});
|
|
||||||
|
|
||||||
const imgData = canvas.toDataURL("image/png");
|
|
||||||
const pdf = new jsPDF({
|
|
||||||
orientation: "portrait",
|
|
||||||
unit: "mm",
|
|
||||||
format: "a4",
|
|
||||||
});
|
|
||||||
|
|
||||||
const imgWidth = 210;
|
|
||||||
const pageHeight = 297;
|
|
||||||
const imgHeight = (canvas.height * imgWidth) / canvas.width;
|
|
||||||
|
|
||||||
pdf.addImage(imgData, "PNG", 0, 0, imgWidth, imgHeight);
|
|
||||||
|
|
||||||
const paymentId = data.razorpayPaymentDetails.paymentId;
|
|
||||||
pdf.save(`Invoice_${paymentId}.pdf`);
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Error generating PDF:", error);
|
|
||||||
alert("Failed to generate PDF. Please try again.");
|
|
||||||
} finally {
|
|
||||||
setIsGenerating(false);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const payment = data.razorpayPaymentDetails;
|
const payment = data.razorpayPaymentDetails;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user