mrafiqk / html-pdf-node

190 stars 118 forks source link

Unable to render pdf object in html after conversion #106

Open PrabhuPuredla95 opened 1 year ago

PrabhuPuredla95 commented 1 year ago

EJS file

<!DOCTYPE html>
<html>
  <head>
    <title>PDF Embedding</title>
  </head>
  <body>
    <h1>Embedded PDF</h1>
    <object
      data="<%= endpoint %>/images/candidate_hiring_guide/JONATHAN_MA_RESUME.pdf"
      type="application/pdf"
      width="100%"
      height="500px"
    >
      <p>
        Embedded PDF viewer is not supported in your browser. Download the PDF
        <a
          href="<%= endpoint %>/images/candidate_hiring_guide/JONATHAN_MA_RESUME.pdf"
          >here</a
        >.
      </p>
    </object>
  </body>
</html>

NodeJS

const html = await ejs.renderFile(
      path.join(__dirname, "./../../", "views/templates/test.ejs"),
      { endpoint: process.env.API_ENDPOINT }
    );

    let file = { content: html };
    html_to_pdf.generatePdf(file, options).then((pdfBuffer) => {
      res.setHeader("Content-Type", "application/pdf");
      res.setHeader(
        "Content-Disposition",
        'attachment; filename="example.pdf"'
      );
      res.send(pdfBuffer);
    });

PDF file is not rendering at all, it just shows object fallback.