I am working with the page.printToPDF module in a Node.js project to generate a PDF with custom page numbers using the footerTemplate. I want to skip the page number on the first page but still generate it. The page numbers should start from page 2 onwards.
I understand that we can use the footerTemplate to insert page numbers, but I’m unsure how to skip numbering on the first page while still generating it in the PDF output.
How can I configure page.printToPDF to:
-
Generate the first page without a page number.
-
Start numbering from page 2, but include the first page in the final output?
I tried using the pageRanges option to skip the first page, but it doesn’t generate page 1 at all. Here’s the code I used
const pdf = await page.printToPdf({
path: 'output.pdf',
format: 'A4',
printBackground: true,
displayHeaderFooter: true,
footerTemplate: `<div style="font-size:12px;width:100%;text-align:right;"><span class="pageNumber"></span></div>`,
pageRanges: '2-', // This skips page 1 entirely, but I want to generate page 1 without numbering
});
await browser.close();
})();
This works to start printing from page 2, but it completely excludes page 1 from the PDF. I need to include page 1 in the document but without any page number on it. How can I achieve that?