2

I want to create a pdf using puppeteer/PDFOptions . It contains a base64 encoded image inside the headerTemplate:

await page.pdf({
  displayHeaderFooter: true,
  printBackground: true,
  headerTemplate:
    '<img class="header-logo" src="data:image/png;base64,${headerimgtry}" style="height:100px; width:100px">',
  footerTemplate: '<h1">Footer</h1>',
  margin: "30px",
  format: "A4",
  path: "output.pdf",
});

(source)

But instead of the image it only shows a placeholder:

How can I correctly display the image in the pdf?

cachius
  • 1,743
  • 1
  • 8
  • 21
Bala Kumar
  • 31
  • 2

1 Answers1

1

I'm using a different templating engine and recently came across this issue. Escaping img/png with a forward-slash to img//png fixed it for me.

Jonathan S.
  • 5,837
  • 8
  • 44
  • 63