When I try to add a header and footer template to the PDF generated by puppeteer, I am facing an issue where the CSS I added is not being fully applied.
await page.pdf({
path: filePath,
format : 'A4',
printBackground : true,
margin : { top : 35, bottom: 45},
displayHeaderFooter : true,
headerTemplate : `
<div style="height: 20px; display: flex; align-items: center; justify-content: space-between; font-size: 6px; font-family: Arial, Helvetica, sans-serif; letter-spacing: 0.5px;">
<span class="date"></span>
<span class="title"></span>
<span class="pageNumber"></span>
</div>`,
footerTemplate : `<span class="pageNumber" style="font-size: 20px;"></span>`
})
In my browser tests, this HTML code provided the correct output. However, the font-size
seemed off in the PDF compared to the browser rendering. For example, when I set font-size : 16px
in the browser, it displayed perfectly, but in the PDF the font appeared too large.
I expected the justify-content
property to work as intended, but unfortunately everything was aligned to the left side instead of spaced between elements.
Which CSS properties will the PDF generation respond to correctly?