Open sumantripathi opened 1 year ago
Hi @sumantripathi I used the same html-pdf
package to generate a pdf for the customer's receipt. I also downloaded it and stored it in a directory I called pdf and it works just fine. This is how I did it.
import ejs from "ejs";
import pdf from "html-pdf";
const options = {
height: "11.25in",
width: "8.5in",
header: {
height: "2mm",
},
footer: {
height: "10mm",
},
};
export const generatePDF = async (details, ejsFileName, pdfFileName) => {
return new Promise((resolve, reject) => {
const ejsFilePath = `${process.cwd()}/src/assets/mails/${ejsFileName}.ejs`;
ejs.renderFile(ejsFilePath, { details }, null, (err, data) => {
if (err) {
console.log("Error rendering EJS file:", err);
reject(err);
} else {
const pdfFilePath = `${process.cwd()}/src/assets/pdf/${pdfFileName}.pdf`;
pdf.create(data, options).toFile(pdfFilePath, (err) => {
if (err) {
console.log("Error generating PDF:", err);
reject(err);
} else {
console.log("PDF generation successful.");
resolve(true);
}
});
}
});
});
};
I hope this helps
Hello All,
I have used npm package 'html-pdf' to generate and downloaded a pdf through streaming . But I wonder why my generated pdf stored in TMP directory with name 'html-pdf-$someid'.
Any help will be highly appreciated please . Thanks