donationReceipt = async (req) => {
try {
const { id } = req.query;
let donationReceipt = await TblmanualDonation.findOne({
where: {
id : id
},
include: {
model : TblmanualDonationItem, as:"manualItemDetails", attributes: ['type', 'remark', 'amount']
},
attributes : ["id", [literal('DATE(donation_date)'), 'donation_date'], "ReceiptNo", "phoneNo", "name", "address"],
raw: true,
nest: true
});
const filePath = path.join(__dirname, '../public/uploads/', 'Receipt.ejs');
console.log(filePath);
const pdfOptions = {
format: 'A3',
printBackground: true,
};
const toWords = new ToWords({
localeCode: 'hi-IN',
});
const amount = toWords.convert(donationReceipt.manualItemDetails.amount);
const template = await ejs.renderFile(filePath, {
donationReceipt: donationReceipt,
amount: amount
});
const filename = path.join(__dirname, `../public/uploads/pdf/${id}.pdf`);
console.log(filename)
pdf.create(template, pdfOptions).toFile(filename, function(err) {
if (err) {
console.log(err);
}
console.log("Pdf send successfully");
});
return donationReceipt;
} catch (error) {
throw error
}
};
The PDF is saved successfully but in the PDF all properties are not displaying as mentioned in template (I am using html-pdf library).
In pdfOptions
, I am trying all the options but still not getting the proper output