I am attempting to generate a PDF from an HTML string using Puppeteer with Node.js. While inline styles within the head section are applied correctly, styles from locally linked .css files specified with an absolute path do not work. Below is my implementation:
generatePDF: async (htmlContent, outputFile) => {
const browserInstance = await puppeteer.launch({
headless: true
});
const newPage = await browserInstance.newPage();
await newPage.setContent(htmlContent, {
waitUntil: 'domcontentloaded'
});
await newPage.pdf({
format: 'A4',
path: outputFile,
printBackground: true
});
await browserInstance.close();
}
The HTML head section contains the following:
.container {
padding-top: 15pt;
}
I also attempted using a URL for the CSS file, but it did not resolve the issue.