I'm currently trying to see if there's a way I can remove page breaks in my puppeteer PDF, as some of the page breaks in my current PDF setup are cutting off text in a weird way. Screenshot of what I'm talking about:
My puppeteer code:
app.get("/:companyId/pdf", (req, res) => {
(async () => {
try {
const browser = await puppeteer.launch({ args: ['--no-sandbox'] });
const page = await browser.newPage();
const url =
process.env.WEBSITE_URL + `/${req.params.companyId}/report-internal`;
await page.goto(url, { waitUntil: "networkidle0" });
const buffer = await page.pdf({ format: "A4", printBackground: true });
res.type("application/pdf");
res.send(buffer);
browser.close();
} catch (error) {
console.error(error);
res.status(500).send("PDF cannot be generated.");
}
})();
});
Is it possible to generate one long, continuous PDF with Puppeteer? That would be ideal. I've tried to set custom CSS print styles to prevent page breaks after certain elements, but so far, I haven't had any luck. Any help is much appreciated.
EDIT: I found a temporary fix that isn't the most beautiful, but works. I had to manually define the width and height of my document inside the page.pdf function as follows:
const buffer = await page.pdf({ printBackground: true, width: 800, height: 3800 });
If there's a better fix for this, that'd be awesome. But in case anyone stumbles across this, that's what worked for me.