Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Short answer: Puppeteer has no documented option that hides a header or footer only on page one. displayHeaderFooter is global for the PDF, and headerTemplate/footerTemplate are reused on every page. For dependable first-page differences, either validate a print-CSS workaround on your exact Chromium build or render page one separately and merge the PDFs.

What Puppeteer actually supports

The PDF API exposes one switch for page headers and footers: displayHeaderFooter. Its documented default is false. When you set it to true, Puppeteer applies the supplied templates throughout the generated document.

Requirement Documented setting Result
No header or footer anywhere displayHeaderFooter: false (or omit it) Neither template is printed.
Header/footer on every page displayHeaderFooter: true plus templates The same configured templates are used on all pages.
Hide only page one No documented PDF option Use a tested CSS experiment or separate rendering and PDF merging.

The templates are HTML strings. Puppeteer supplies special classes for values such as the current date, document title, URL, page number and total page count. Those classes insert values; they do not provide a JavaScript condition that can detect “first page” and switch markup off. In particular, pageNumber is not a conditional programming environment.

Page.pdf() generates output with the print CSS media type by default. That matters if you try to alter page margins with @page rules, because print-specific CSS is active even though the first-page behavior is not guaranteed by the PDF API.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
Epson EcoTank ET-2800 Wireless Color All-in-One Supertank Printer - Black
  • INNOVATIVE CARTRIDGE-FREE PRINTING — No more dealing with lots of tiny ink cartridges; With this wireless document and photo printer each ink bottle set is equivalent to about 90 individual cartridges²
  • LESS FREQUENT INK REPLACEMENT — Replacement ink bottles don't have to be changed nearly as often as ink cartridges¹; When you choose this combination printer, scanner and copier you can print up to 4,500 pages black/7,500 color³
  • COLOR PRINTING — Up to 2 years of ink in the box4 (and with every replacement ink set) for fewer out-of-ink frustrations
  • ZERO CARTRIDGE WASTE — By using an Epson EcoTank printer you can help reduce the amount of cartridge waste ending up in landfills
  • HOME PRINTER DESIGNED FOR RELIABILITY — The Epson EcoTank ET-2800 All-in-One Supertank Color Printer creates vivid, detailed prints and documents thanks to Micro Piezo Heat-Free Technology; Fire off 10 ISO pages per minute1 to easily finish large jobs

Use a global header or footer when a first-page exception is unnecessary

This is the supported, simplest configuration. Reserve enough top and bottom margin for the templates; otherwise body content can overlap them.

import puppeteer from 'puppeteer';

const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://example.com', { waitUntil: 'networkidle0' });

await page.pdf({
  path: 'report.pdf',
  format: 'A4',
  printBackground: true,
  displayHeaderFooter: true,
  headerTemplate: '<div style="font-size:9px;width:100%;text-align:center;">Quarterly report</div>',
  footerTemplate: '<div style="font-size:9px;width:100%;text-align:center;">Page <span class="pageNumber"></span> of <span class="totalPages"></span></div>',
  margin: {
    top: '50px',
    bottom: '50px',
    left: '36px',
    right: '36px'
  }
});

await browser.close();

Template CSS is safest when it is inline. External stylesheets, web fonts and page JavaScript are not a reliable way to style the tiny header/footer document. Test the generated PDF, not just the page in a normal browser tab.

Why there is no first-page switch

The options model describes whether to show the header and footer, then accepts one header template and one footer template. It does not define a per-page callback, a first-page flag, or a template expression language. A template containing a page-number span will receive a number, but Puppeteer does not promise that you can use that value to conditionally remove the surrounding HTML.

Consequently, code such as this does not implement the requested behavior:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
await page.pdf({
  displayHeaderFooter: true,
  headerTemplate: '<span class="pageNumber"></span> && <div>Header</div>'
});

The text is merely template markup. It is not evaluated as JavaScript, and the special classes are replaced with values during PDF generation.

Approach 1: test a print-CSS first-page workaround

Developers sometimes combine @page:first with different page-margin boxes so the first page has no room for a running header or footer. This is a CSS experiment, not a documented Puppeteer feature. A historical Puppeteer issue from 2018 (Puppeteer 1.3.0) reported inconsistent footer behavior with this technique; that report cannot establish how a current Chromium build behaves.

Rank #2
Sale
Epson EcoTank Photo ET-8550 Wireless Wide-Format All-in-One Tank Printer
  • CARTRIDGE-FREE PRINTING — Print lab-quality photos, graphics and creative projects; Get vibrant colors and sharp text with Epson's high-accuracy printhead and Claria ET Premium 6-color inks
  • INK BOTTLES — Save on photos1 and creative projects with affordable in-house printing; All-in-one printer allows you to print 4" x 6" photos for about 4 cents each vs. 40 cents with traditional ink cartridges1
  • LESS FREQUENT INK REPLACEMENT — Replacement ink bottles don't have to be changed nearly as often as ink cartridges¹; Printer, scanner and copier lets you print up to 6,200 color pages³
  • PRINT FOR LONGER — Up to 2 years of ink in the box² (and with every replacement ink set) for fewer out-of-ink frustrations with this wireless printer
  • ZERO CARTRIDGE WASTE — Epson EcoTank printer helps reduce the amount of cartridge waste ending up in landfills; Cartridge-free printer uses high-yield ink bottles; Each replacement ink bottle set is equivalent to about 100 individual ink cartridges⁴

If you choose to investigate it, make the test explicit and versioned:

<style>
  @page {
    margin: 60px 40px 60px 40px;
  }
  @page:first {
    margin-top: 20px;
    margin-bottom: 20px;
  }
</style>
  1. Run the test with the exact Puppeteer package and Chromium revision used in production.
  2. Generate a document of at least three pages, with enough content to force real page breaks.
  3. Inspect both the header and footer on pages 1, 2 and 3; do not infer success from a one-page PDF.
  4. Repeat with long headings, images, different fonts and a page break immediately after the first section.
  5. Pin the browser version if the result is acceptable, and re-run the PDF test whenever Puppeteer or Chromium changes.

If either margin box still appears on page one, or disappears on later pages, treat the method as unsupported in that deployment and use separate rendering instead.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Approach 2: render page one and the remaining pages separately

When the first page has genuinely different branding or spacing, separate documents provide the clearest control. Render a cover/first page with no templates, render the body with the normal templates, then merge the resulting PDFs in your application. This is an engineering workaround, not a Puppeteer toggle.

import puppeteer from 'puppeteer';
import { PDFDocument } from 'pdf-lib';

const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setContent(html, { waitUntil: 'networkidle0' });

// First page: no header or footer.
const firstPagePdf = await page.pdf({
  format: 'A4',
  printBackground: true,
  displayHeaderFooter: false,
  pageRanges: '1',
  margin: { top: '24px', bottom: '24px', left: '36px', right: '36px' }
});

// Remaining pages: reserve space and show the running footer.
const remainingPdf = await page.pdf({
  format: 'A4',
  printBackground: true,
  displayHeaderFooter: true,
  headerTemplate: '<div style="font-size:9px;width:100%;text-align:center;">Report</div>',
  footerTemplate: '<div style="font-size:9px;width:100%;text-align:center;">Page <span class="pageNumber"></span> of <span class="totalPages"></span></div>',
  pageRanges: '2-9999',
  margin: { top: '50px', bottom: '50px', left: '36px', right: '36px' }
});

const output = await PDFDocument.create();
for (const bytes of [firstPagePdf, remainingPdf]) {
  const source = await PDFDocument.load(bytes);
  const pages = await output.copyPages(source, source.getPageIndices());
  pages.forEach((p) => output.addPage(p));
}
await Bun.write('report.pdf', await output.save());
await browser.close();

The example uses pageRanges to illustrate the split. In practice, you should ensure that the first render really contains the intended first page and that the second render starts at the correct content. If your HTML reflows when margins change, page two in the second render may not correspond to page two in the combined document. A robust production design often uses a dedicated cover element or a deliberate page break, then validates the page count and visible content after merging.

Details to verify after merging

  • Page numbering: the second render’s pageNumber normally starts at 1, so its footer may need an application-level offset if the final PDF should show page 2, page 3 and so on.
  • Total pages: totalPages refers to the document being rendered, not automatically to the final merged file.
  • Margins and fonts: the two renders can wrap text differently. Keep width, scale, fonts and print settings aligned except for the header/footer change.
  • Links and metadata: merging libraries differ in how they preserve outlines, annotations, forms and PDF metadata. Check the final file if those features matter.
  • Memory: large PDFs are held as byte arrays during merging. Stream or process in smaller batches when documents are large.

Template, margin and page-break settings that commonly matter

Reserve header and footer space

Set margin.top and margin.bottom to values larger than the rendered template. A template does not push body content down automatically in a way that protects you from overlap.

Use print media deliberately

Because PDF generation uses print media by default, put print-only rules in @media print and check whether your screen styles are being overridden. Use page.emulateMediaType('screen') only when you intentionally want screen styles; that changes the document being printed and is separate from first-page header logic.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
HP Smart Tank 5000 Ink Tank Printer | 2 Years of Ink Included | All-in-One
  • SET IT UP ONCE AND PRINT WITH CONFIDENCE. No complicated maintenance. Just easy, reliable printing you can count on.
  • INK FOR YEARS. NOT MONTHS. Up to 2 years of ink included. Get thousands of pages of cartridge-free printing. More pages, less hassle
  • KEEPS PRINTING WELL AFTER COMPETITORS HAVE QUIT. No complex maintenance. Sharper text, richer colors.[2] Only with HP Smart Tank
  • PREMIUM SUPPORT - Strong technical expertise to solve issues faster
  • THE LAST PRINTER YOU'LL EVER NEED. Enjoy years of refillable, cartridge-free printing.

Control breaks in the document

Use print CSS such as break-before: page or break-inside: avoid where supported by your target browser, but do not assume a break will remain identical after changing margins. A first-page cover section with an explicit break is easier to reason about than relying on incidental content height.

Troubleshooting

The header appears on page one

That is the expected result when displayHeaderFooter: true is used with a single template. Remove the global templates only for a separate first-page render, or test the CSS method on the exact browser version.

The footer overlaps body text

Increase the bottom margin, reduce the template’s font and padding, and inspect a page with the longest footer content. Header/footer HTML has its own layout; body CSS margins do not reserve that space.

Page numbers are wrong after merging

The second PDF starts its own numbering sequence. Add the number of pages in the first PDF when displaying a final-page number, or apply page labels with a PDF library after merging. Also remember that totalPages came from each source render.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

@page:first works locally but not in production

Compare Puppeteer and Chromium versions, operating-system fonts, and the exact HTML. This workaround is version-sensitive. If you cannot pin and test the environment, use separate rendering.

The PDF is blank or missing late-loading content

Wait for navigation and application readiness before calling page.pdf(). Depending on the site, that can mean waitUntil: 'networkidle0', waiting for a specific selector, or waiting for an application promise. A network-idle event alone does not guarantee that a client-side chart has finished drawing.

Rank #4
Sale
NDYIN Portable Printers Wireless for Travel, N80 Bluetooth Thermal Printer
  • Wireless Bluetooth Printer: Portable thermal printer compatible with iPhone, Android phones, iPad and tablet computers via Bluetooth. For smartphones, please download the "Nada Print" App. You can also connect to laptops and computers for printing using a USB-C cable. (Note: Laptops and computers can only be connected via USB and require the installation of a driver first. Bluetooth connection is not supported.)
  • No-ink printing: Only supports US Letter and A4 size thermal paper.(Doesn't support regular paper) The no-ink portable thermal printer uses direct thermal technology, requiring no ink, toner or ribbons, making it environmentally friendly, cost-effective and time-saving. The thermal printer package comes with a roll of US Letter thermal printing paper. Note: When installing the paper, remember to switch the paper size switch on APP
  • Clear Print: NDYIN N80 portable thermal printer adopts high-definition printing technology, with a 203DPI resolution to provide you with clear printing results. This mobile printer is compatible with roll paper, folded paper and tattoo transfer paper, supporting printing from your mobile phone PDF, Word, pictures and web pages anytime and anywhere. It is recommended to use our NDYIN thermal paper to achieve good printing quality
  • Portable wireless printer for travel: The thermal printer is equipped with a built-in 1500mAh rechargeable battery, which can print 160 sheets of 8.5" x 11" thermal paper after being fully charged. It weighs only 1.5 pounds and is compact in size. This ink-free portable printer can be easily carried in a backpack or briefcase! It is perfect for business travel, cars, small offices, construction sites, schools and homes. You can print documents, contracts, invoices and boarding passes anytime and anywhere
  • The N80 thermal printer has a wide range of uses. The package includes the N80 printer, a roll of US Letter paper(7m/roll), a user manual, a guide card, a type-C soft cable and a type C adapter. Note: The charging adapter is not included. Special thermal paper is required for use; ordinary paper cannot be used. This ink-free portable thermal printer is suitable for various scenarios such as home, school, travel, office, and outdoor, meeting the printing needs of different groups of people. This tattoo template printer is also compatible with tattoo transfer paper, making it an ideal choice for tattoo art

Images or backgrounds are absent

Use printBackground: true, make sure image URLs are reachable from the browser, and wait for the images or fonts your page requires. Cross-origin authentication and CSP rules can prevent resources from loading even when the HTML itself is present.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Performance, reliability and cost choices

Method Operational cost Reliability Best use
Global templates One render, minimal code Highest because it uses the documented API Header/footer on every page
Print-CSS experiment One render, additional regression testing Depends on browser version and layout A controlled environment where you can pin and test Chromium
Separate render and merge Two renders plus PDF assembly and memory Most control, but more failure points Strict first-page design, cover pages or different margins

For batch generation, reuse a browser process and create isolated pages rather than launching Chromium for every document. Limit concurrency to what your CPU and memory can sustain. Cache stable assets such as fonts where your deployment permits it, but invalidate caches when the visual version changes. Keep a regression fixture containing a cover, several body pages, long text, images and a final page; compare page count and rendered images after dependency upgrades.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Or skip the browser setup

If your requirement is simply to obtain a clean PDF or screenshot from a URL rather than maintain Puppeteer infrastructure, ScreenshotNeo provides a GET-based API. Its PDF options include paper size, margins, landscape mode and page ranges, along with waits, custom CSS and JavaScript, cookies, headers and other capture controls.

curl -G "https://api.screenshotneo.com/v1/shot" 
  -d access_key=YOUR_API_KEY 
  --data-urlencode url=https://example.com/report 
  -d format=pdf 
  -o report.pdf

See the ScreenshotNeo documentation for the current parameter names and PDF options. The same endpoint can be called from Python:

import requests

r = requests.get(
    "https://api.screenshotneo.com/v1/shot",
    params={"access_key": "YOUR_API_KEY", "url": "https://example.com/report", "format": "pdf"},
    timeout=90,
)
r.raise_for_status()
open("report.pdf", "wb").write(r.content)

Or Node.js:

const q = new URLSearchParams({
  access_key: 'YOUR_API_KEY',
  url: 'https://example.com/report',
  format: 'pdf'
});
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
await Bun.write('report.pdf', new Uint8Array(await res.arrayBuffer()));
  • Cookie and consent banners, newsletter popups and chat widgets are removed before the shot; each cleanup step can be turned off.
  • Bot checks or CAPTCHAs, blank pages, timeouts, failed loads and cache hits are not billed. Response headers identify the page verdict and whether it was billed.
  • An MCP server exposes take_screenshot, get_page_info and capture_pdf to Claude, Cursor and other MCP clients.
  • The Free plan includes 1,000 shots per month without a card; paid plans start at $5 for 3,000 shots. Every feature is included on every plan.

Create a free ScreenshotNeo account to try the 1,000 monthly shots without adding a card.

Frequently Asked Questions

Can I use JavaScript inside headerTemplate to detect pageNumber?

No. Puppeteer treats the template as HTML and replaces documented special classes with values; it does not execute template JavaScript or expose a first-page conditional.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Will pageRanges alone hide a footer on page one?

No. pageRanges selects which pages are rendered in a particular PDF call. It does not make one template conditional within a single render; you need separate renders if the first page must differ.

Which method should I choose for a regulated or repeatable report?

Use the documented global setting when every page is identical. For a first-page exception, prefer a separate-render-and-merge pipeline with a pinned browser version and automated PDF checks rather than relying on unverified CSS behavior.

Quick Recap

Bestseller No. 3
HP Smart Tank 5000 Ink Tank Printer | 2 Years of Ink Included | All-in-One
HP Smart Tank 5000 Ink Tank Printer | 2 Years of Ink Included | All-in-One
PREMIUM SUPPORT - Strong technical expertise to solve issues faster; THE LAST PRINTER YOU'LL EVER NEED. Enjoy years of refillable, cartridge-free printing.
$194.03

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.