0
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

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • The docs mention in the Options, doesn't look like you are using it? `"base": "file:///home/www/your-asset-path/"`, // Base path that's used to load files (images, css, js) when they aren't referenced using a host https://www.npmjs.com/package/html-pdf?activeTab=readme – Jorge Campos Aug 29 '23 at 20:14
  • Thank-you for your support!!! Now image is properly rendering in pdf but still the CSS properties are not working. The text got override in left side. – Lokendra Kumar Aug 31 '23 at 15:52

0 Answers0