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

If a Puppeteer PDF header or footer is missing, first enable it: displayHeaderFooter: true. Then provide a non-empty headerTemplate and/or footerTemplate HTML string, and reserve space with top or bottom margins. Puppeteer keeps headers and footers disabled by default, so a valid template alone is not enough.

The minimal fix

Start with a deliberately simple template and explicit margins. Puppeteer supports the special classes date, title, url, pageNumber, and totalPages; it replaces those elements with document values when the PDF is generated.

const browser = await puppeteer.launch();
const page = await browser.newPage();

await page.goto('https://example.com', { waitUntil: 'networkidle0' });

await page.pdf({
  path: 'output.pdf',
  displayHeaderFooter: true,
  headerTemplate: '<div class="header"><span class="title"></span></div>',
  footerTemplate: '<div class="footer"><span class="pageNumber"></span> / <span class="totalPages"></span></div>',
  margin: {
    top: '60px',
    bottom: '60px'
  }
});

await browser.close();

The margin values are starting points, not universal measurements. Increase them if your template is clipped or overlaps page content; decrease them only after checking the rendered PDF.

Check the template itself

Use the correct option names

The options are case-sensitive. The switch is displayHeaderFooter, not displayHeaderAndFooter. The strings are headerTemplate and footerTemplate. A typo, an empty string, or a variable that is undefined produces a PDF without the expected content.

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

Keep the first diagnostic markup simple

Begin with plain text and the documented value classes. For example:

headerTemplate: '<div>Invoice</div>',
footerTemplate: '<div>Page <span class="pageNumber"></span> of <span class="totalPages"></span></div>'

Once that appears, add your layout and styling incrementally. The PDF options document HTML templates and the supported injected-value classes, but it does not promise that arbitrary page styles, external stylesheets, or external assets will be available inside the template. Treat those dependencies as variables to verify rather than as guaranteed behavior.

Use the special classes exactly

  • date inserts the generated date.
  • title inserts the document title.
  • url inserts the page URL.
  • pageNumber inserts the current page number.
  • totalPages inserts the total page count.

The same classes are supported in the footer. They are intended for the template, not as a general-purpose data-binding system for arbitrary variables.

Reserve space so content does not cover the header or footer

If margin is omitted, Puppeteer documents that no margins are set. A header can therefore render outside the usable content area or collide with the first line of the page. Set at least the relevant side explicitly:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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⁴
margin: {
  top: '72px',
  bottom: '54px',
  left: '36px',
  right: '36px'
}

There is no single correct margin. Match the value to the template’s actual height, font size, and line wrapping. Inspect several pages, including pages where the body starts with a large heading or an image. A margin that works on page one can still be too small when a header wraps.

Resolve page-size and CSS precedence

Unexpected clipping can come from competing paper-size declarations rather than from the template. Puppeteer applies these rules:

Layout choice What controls the paper size Important precedence
format A named paper format format takes precedence over width and height.
width and height Explicit dimensions They are ignored when format is also supplied.
CSS @page Your stylesheet’s page rule It wins when preferCSSPageSize: true.
Default CSS-page preference Puppeteer paper settings With preferCSSPageSize: false (the default), Puppeteer scales content to fit the selected paper size.

Choose one source of truth while diagnosing. Remove a conflicting format, check the supplied dimensions, or enable preferCSSPageSize when the CSS @page rule is intentionally authoritative.

Account for print media and color changes

page.pdf() generates using the print CSS media type. Rules inside @media print can therefore hide, resize, or restyle elements compared with the browser window you inspected. If the design should use screen media instead, set it before generating the PDF:

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.
await page.emulateMediaType('screen');
await page.pdf({
  path: 'screen-styled.pdf',
  displayHeaderFooter: true,
  headerTemplate: '<div><span class="title"></span></div>',
  footerTemplate: '<div><span class="pageNumber"></span> / <span class="totalPages"></span></div>',
  margin: { top: '60px', bottom: '60px' }
});

Print output can also adjust colors. When exact colors matter, Puppeteer documents the CSS property -webkit-print-color-adjust for requesting the intended color treatment. Apply it in the page styles and verify the resulting PDF rather than assuming screen colors will carry over unchanged.

Use a complete, controlled generation sequence

A reliable script makes the order of operations explicit: load the page, select the media type, then call page.pdf() with the display switch, templates, margins, and one page-size strategy.

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch();
  try {
    const page = await browser.newPage();

    await page.goto('https://example.com/report', {
      waitUntil: 'networkidle0'
    });

    // Omit this line to use the documented print media default.
    await page.emulateMediaType('screen');

    await page.pdf({
      path: 'report.pdf',
      displayHeaderFooter: true,
      headerTemplate: [
        '<div style="width:100%; font-size:9px; padding:0 24px;">',
        '<span class="title"></span>',
        '</div>'
      ].join(''),
      footerTemplate: [
        '<div style="width:100%; font-size:9px; padding:0 24px; text-align:right;">',
        'Page <span class="pageNumber"></span> of ',
        '<span class="totalPages"></span>',
        '</div>'
      ].join(''),
      margin: {
        top: '64px',
        bottom: '48px',
        left: '24px',
        right: '24px'
      },
      format: 'A4'
    });
  } finally {
    await browser.close();
  }
})();

If your stylesheet defines a deliberate CSS @page size, replace the format choice with preferCSSPageSize: true and remove the competing paper-size settings.

A diagnostic sequence for a missing or broken template

  1. Confirm the switch. Log or inspect the options object and verify that displayHeaderFooter is the boolean true.
  2. Confirm the selected property. Make sure the header HTML is in headerTemplate and the footer HTML is in footerTemplate, with a non-empty string in the property you expect to render.
  3. Reduce the markup. Replace the design with one plain div and one documented special class. This separates template rendering from CSS, fonts, images, and JavaScript.
  4. Add space. Set explicit top and bottom margins. If the header appears but is cut off, increase the corresponding margin and regenerate.
  5. Check paper-size conflicts. Decide whether format, explicit dimensions, or CSS @page should control the page.
  6. Check media rules. Review @media print and try page.emulateMediaType('screen') only when screen styling is the intended result.
  7. Inspect the PDF itself. Do not rely only on a browser preview. Check the first page, a middle page, and the last page for wrapping, overlap, and page-number values.

Common symptoms, causes to check, and fixes

Symptom Check first Practical fix
No header or footer at all displayHeaderFooter is absent or false; the template property is empty or misspelled. Set the switch to true and use a non-empty HTML string.
Page numbers are blank The class name differs from pageNumber or totalPages. Use the documented class names exactly and inspect the generated PDF.
Header overlaps body content No top margin, or the margin is shorter than the rendered header. Add or increase margin.top.
Footer is clipped No bottom margin, a wrapped footer, or insufficient paper space. Add or increase margin.bottom; simplify the footer while testing.
Layout changes after adding format format overrides width and height. Keep one page-size strategy and remove conflicting settings.
CSS page size is ignored preferCSSPageSize remains false. Set preferCSSPageSize: true when the CSS @page rule should win.
Template styling differs from the page The template depends on styles or assets that are not available to it. Use simple inline diagnostic styling, then add dependencies one at a time and verify each output.
Colors differ from the browser PDF generation uses print media and print color handling. Review print CSS, consider emulateMediaType('screen'), and use -webkit-print-color-adjust where exact colors are required.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Fonts, loading, and repeatability

Puppeteer’s PDF guide states that Page.pdf() waits for fonts to load by default. That is useful, but it does not prove that a font issue explains a missing template. If typography is wrong, inspect the generated file and the page’s actual font and CSS inputs. Keep navigation and PDF generation in a consistent sequence, and avoid changing media type or page-size settings between diagnostic runs unless you are testing that specific variable.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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

Or skip the browser setup

When you need a clean page capture or PDF rather than control over Puppeteer’s template HTML, ScreenshotNeo provides a single website-screenshot API request. It accepts the cookie or consent banner like a visitor, then removes more than 60 known consent platforms, newsletter popups, and chat widgets before the capture. You can turn each cleanup step off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed; the response identifies the result with X-Page-Verdict and X-Billed headers. It also offers an MCP server for AI agents, including Claude and Cursor, with take_screenshot, get_page_info, and capture_pdf tools.

Use the API call shown in the ScreenshotNeo documentation:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

The same request in Python:

import requests

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

And in Node.js:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

Every feature is available on every plan. The Free plan includes 1,000 shots each month with no card; paid plans start at $5 for 3,000 shots. If that fits your workflow, create a free ScreenshotNeo account.

Frequently Asked Questions

Can I put ordinary HTML headers inside the page body instead of using headerTemplate?

Yes, but that is a different layout approach. Puppeteer’s repeating PDF header and footer mechanism is controlled by displayHeaderFooter together with headerTemplate and footerTemplate; body HTML will follow normal document flow and will not use the injected page-number classes.

Free tools Windows power users keep installed

One-click scans. No signup required.

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

Why does a template work on one URL but not another?

The template is generated during PDF creation, while the page can supply different print CSS, page-size rules, fonts, and content heights. Compare the two URLs with the same PDF options and reduce the template to plain HTML to isolate the differing input.

Do headers and footers require a separate PDF page for every section?

No. A single headerTemplate and footerTemplate are applied by the PDF generation options, with pageNumber and totalPages available for pagination values.

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.