Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pdf saved in TMP directory #697

Open
sumantripathi opened this issue Jan 10, 2023 · 1 comment
Open

Pdf saved in TMP directory #697

sumantripathi opened this issue Jan 10, 2023 · 1 comment

Comments

@sumantripathi
Copy link

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

@czarjulius
Copy link

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);
          }
        });
      }
    });
  });
};
Screenshot 2023-08-10 at 1 33 54 PM

I hope this helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants