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.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

To print a header or footer in a Puppeteer PDF, set displayHeaderFooter: true and pass HTML strings to headerTemplate and/or footerTemplate. Puppeteer fills five documented classes—date, title, url, pageNumber, and totalPages—when Chromium renders the PDF. Reserve space with the PDF’s top and bottom margins, and remember that page.pdf() uses print CSS unless you explicitly emulate screen media.

Minimal working example

Install Puppeteer, create a page, and enable the templates in the same page.pdf() call:

const puppeteer = require('puppeteer');

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

  await page.setContent(`
    <main>
      <h1>Quarterly report</h1>
      <p>Your document content goes here.</p>
    </main>
  `, { waitUntil: 'networkidle0' });

  await page.pdf({
    path: 'report.pdf',
    format: 'A4',
    displayHeaderFooter: true,
    headerTemplate: `
      <div style="font-size:9px; width:100%; padding:0 24px; color:#555;">
        <span class="title"></span>
        <span style="float:right" class="date"></span>
      </div>`,
    footerTemplate: `
      <div style="font-size:9px; width:100%; padding:0 24px; color:#555; text-align:center;">
        Page <span class="pageNumber"></span>
        of <span class="totalPages"></span>
      </div>`,
    margin: {
      top: '60px',
      bottom: '50px',
      left: '24px',
      right: '24px'
    }
  });

  await browser.close();
})();

The option defaults to displayHeaderFooter: false, so templates are ignored until you turn it on. Both templates are HTML strings, not selectors pointing at elements in the page body.

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

Which dynamic values can a template print?

Class Value inserted by Chromium Typical use
date Formatted print date Report generation date
title Document title Heading or running report name
url Document location Source URL in audits
pageNumber Current page number “Page 2”
totalPages Total page count “of 8”

Use the class names exactly as shown. Puppeteer replaces their contents during PDF generation. Ordinary page-body selectors, custom class names, or JavaScript that runs after PDF creation do not receive these values automatically.

#1 Best Overall
Amazon Basics Multipurpose Copy Printer Paper, 8.5 x 11 Inches, 20 lb, 92 Bright, White, 1 Ream (500 Sheets), Jam-Free
  • 1 ream (500 sheets) of 8.5 x 11 white copier and printer paper for home or office use
  • Multipurpose letter size copy paper works with laser/inkjet printers, copiers and fax machines
  • Smooth 20lb weight paper for consistent ink and toner distribution; dries quickly and resists paper jams
  • Bright white paper (92 GE; 104 Euro) offers great contrast for crisp printing and vivid color
  • Virgin copy paper providing professional quality results; acid-free to prevent yellowing

How the page body and templates are rendered

Print media is the default

page.pdf() generates the document with the print CSS media type. Rules inside @media print therefore apply, and screen-only layouts may change. If the PDF should match the screen design, call this before generating it:

await page.emulateMediaType('screen');
await page.pdf({
  path: 'screen-styled.pdf',
  displayHeaderFooter: true,
  headerTemplate: '<div class="title"></div>',
  footerTemplate: '<div class="pageNumber"></div>',
  margin: { top: '48px', bottom: '40px' }
});

Choose one media mode deliberately. Switching to screen affects the body’s responsive and print rules; it does not remove the need to enable header and footer display.

Colors are adjusted for printing

Chromium modifies colors for print output by default. When brand colors or backgrounds must remain exact, add this to the relevant body or component CSS:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
* {
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

Exact color adjustment can increase ink or produce a result that is less printer-friendly, so apply it only where fidelity matters.

Rank #2
HP Printer Paper | 8.5 x 11 Paper | Copy &Print 20 lb | 1 Ream Case - 500 Sheets| 92 Bright | FSC Certified | 200060
  • HP Papers is sourced from renewable forest resources and has achieved production with 0% deforestation in North America. Each ream is wrapped in a polyurethane coated paper wrapper to protect the cut sheets from moisture damage
  • Sheet size – 8.5 x 11; Thickness – 20 pounds; Brightness – 92 bright white
  • HP Copy&Print20 20 pounds printer paper is Forest Stewardship Council (FSC) certified and contributes toward satisfying credit MR1 under LEED (Leadership in Energy and Environmental Design)
  • All HP Papers provide premium performance on HP equipment, as well as on all other printer and copier equipment; 100% satisfaction guaranteed; ColorLok technology provides more vivid colors, bolder blacks and faster drying
  • Superior quality, reliability, and dependability for high-volume printing at home, at school and in the office; HP Copy&Print20 print and copy paper prevents yellowing over time to ensure a long-lasting appearance for added archival quality

Templates are separate from the document body

Header and footer HTML is repeated by Chromium on each page. It is not part of the page’s normal DOM flow, cannot rely on your body’s layout containers, and should be kept self-contained. Inline styles and simple markup are the most portable choices.

Margins: reserve space for repeating content

The header and footer occupy the margin areas. If the top or bottom margin is smaller than the template’s visual height, the body can appear to collide with it or the template can look clipped. There is no universal pixel value: measure your actual template, then set margin.top and margin.bottom accordingly.

  • Start with a margin larger than the template’s font, padding, and line height.
  • Use the same units consistently (px, in, mm, or cm).
  • Test a one-page document and a document that flows across several pages.
  • Include long titles and localized dates in tests; they can wrap and require more height.

Production-ready pattern with loaded content

For a real URL, wait for navigation and any assets before calling page.pdf(). The following example also sets the title used by the title placeholder and preserves screen colors:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const puppeteer = require('puppeteer');

async function makePdf(url) {
  const browser = await puppeteer.launch({
    headless: true
  });
  try {
    const page = await browser.newPage();
    await page.goto(url, { waitUntil: 'networkidle0', timeout: 60000 });
    await page.emulateMediaType('screen');
    await page.addStyleTag({
      content: `
        @media print {
          * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
        }
      `
    });

    await page.pdf({
      path: 'site-report.pdf',
      printBackground: true,
      displayHeaderFooter: true,
      headerTemplate: `
        <div style="font-size:8px; width:100%; margin:0 20px;">
          <span class="title"></span>
          <span style="float:right" class="url"></span>
        </div>`,
      footerTemplate: `
        <div style="font-size:8px; width:100%; margin:0 20px; text-align:right;">
          <span class="date"></span> ·
          <span class="pageNumber"></span>/<span class="totalPages"></span>
        </div>`,
      margin: { top: '52px', bottom: '42px', left: '20px', right: '20px' }
    });
  } finally {
    await browser.close();
  }
}

makePdf('https://example.com').catch(console.error);

printBackground: true is separate from color adjustment: it asks Puppeteer to include CSS backgrounds, while -webkit-print-color-adjust requests color fidelity.

Rank #3
Amazon Basics Multipurpose Copy Printer Paper, 20 lb, 8.5 x 11 Inches, 3 Reams (1,500 Sheets), 92 Bright White for Home Use
  • 3 ream case (1,500 sheets) of 8.5 x 11 white copier and printer paper for home or office use
  • Multipurpose letter size copy paper works with laser/inkjet printers, copiers and fax machines
  • Smooth 20lb weight paper for consistent ink and toner distribution; dries quickly and resists paper jams
  • Bright white paper (92 GE; 104 Euro) offers great contrast for crisp printing and vivid color
  • Virgin copy paper providing professional quality results; acid-free to prevent yellowing

Why a header or footer is not showing

displayHeaderFooter was omitted

This is the most common cause. Set it to true; its default is false.

The placeholder class is wrong

page-number, currentPage, or a body element with the same name will not be substituted. Use the documented camel-case classes: pageNumber and totalPages, along with date, title, and url.

The template is outside the option object

Pass headerTemplate and footerTemplate directly inside the object supplied to page.pdf(). They are not page navigation options and do not belong in goto() or setContent().

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.

The body overlaps the template

Increase the corresponding top or bottom margin. A large logo, wrapped title, or two-line footer needs more space than a one-line template.

Rank #4
Amazon Basics Multipurpose Copy Printer Paper, 20 lb, 8.5 x 11 Inches, 5 Reams (2,500 Sheets), 92 Bright White
  • 5 ream case (2,500 sheets) of 8.5 x 11 white copier and printer paper for home or office use
  • Multipurpose letter size copy paper works with laser/inkjet printers, copiers and fax machines
  • Smooth 20lb weight paper for consistent ink and toner distribution; dries quickly and resists paper jams
  • Bright white paper (92 GE; 104 Euro) offers great contrast for crisp printing and vivid color
  • Virgin copy paper providing professional quality results; acid-free to prevent yellowing

Colors or layout differ from the browser

Check the active media type first. Print CSS is the default; call page.emulateMediaType('screen') when screen rules are intended. Then decide whether to enable printBackground and color adjustment.

Assets are missing

Wait for navigation, network idle, or a specific application-ready selector before generating the PDF. A header template cannot repair a body that was captured before its fonts or images loaded.

Testing and reliability checklist

  • Generate a short one-page fixture and a multi-page fixture.
  • Verify that page numbers increment and total pages are stable.
  • Test long titles, URLs, dates, and non-Latin text.
  • Check output with both print and screen media if your application supports both.
  • Inspect the first and last page for clipping, overlap, and unexpected blank space.
  • Pin and recheck your Puppeteer version after upgrades; the PDFOptions reference currently displays version 25.12.0, and option behavior can change between releases.

Performance and operational considerations

Header and footer templates add little work compared with launching Chromium, loading the page, and waiting for assets. Reuse a browser process for batches, create isolated pages per job, and close pages reliably. Set navigation and job timeouts appropriate to your content. For deterministic output, control fonts, locale, timezone, and external network dependencies in your own application; the PDF API itself does not provide a universal rendering benchmark.

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

Keep templates small. Complex scripts, external stylesheets, and body-only selectors are common sources of inconsistent output because templates are rendered in a separate print context. Prefer inline CSS and static text around the injected classes.

Best Value
Amazon Basics Multipurpose Copy Printer Paper, 20 lb, 8.5 x 11 Inches, 8 Reams (4,000 Sheets), 92 Bright White, Great for Crisp Ink Printing
  • 8 ream case (4,000 sheets) of 8.5 x 11 white copier and printer paper for home or office use
  • Multipurpose letter size copy paper works with laser/inkjet printers, copiers and fax machines
  • Smooth 20lb weight paper for consistent ink and toner distribution; dries quickly and resists paper jams
  • Bright white paper (92 GE; 104 Euro) offers great contrast for crisp printing and vivid color
  • Virgin copy paper providing professional quality results; acid-free to prevent yellowing
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If you need a screenshot or PDF without maintaining Chromium code, ScreenshotNeo provides a website screenshot API and MCP server. A single GET request can return PNG, JPEG, WebP, or PDF; its cleaning steps accept consent banners and remove more than 60 known consent platforms, newsletter popups, and chat widgets before capture. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status.

For PDF capture, use the API documentation at screenshotneo.com/docs/. The supplied call is:

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}`);

ScreenshotNeo also offers an MCP server with take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account.

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

Choosing the right approach

Need Best fit Reason
Custom running fields inside your own generated report Puppeteer templates Direct control over HTML, CSS, margins, and page lifecycle.
Screen-media fidelity from an existing site Puppeteer plus emulateMediaType('screen') Lets you choose screen rules before PDF generation.
Capture many public pages without browser orchestration ScreenshotNeo One API call, cleaning of common overlays, and no charge for failed or blocked captures.

Frequently Asked Questions

Can I use only a footer template?

Yes. Set displayHeaderFooter: true, provide footerTemplate, and omit headerTemplate. Reserve bottom margin for the footer.

Are page numbers available in the page body?

The automatic values are injected into header and footer templates through pageNumber and totalPages. They are not ordinary body variables.

Why is my title placeholder empty?

The title value comes from the document title. Set a meaningful HTML <title> or otherwise ensure the page has a title before calling page.pdf().

Does changing the header alter the PDF page count?

It can indirectly: larger margins reduce body space, which may create additional pages. Always verify totalPages after changing template height or margins.

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

Quick Recap

Bestseller No. 1
Amazon Basics Multipurpose Copy Printer Paper, 8.5 x 11 Inches, 20 lb, 92 Bright, White, 1 Ream (500 Sheets), Jam-Free
Amazon Basics Multipurpose Copy Printer Paper, 8.5 x 11 Inches, 20 lb, 92 Bright, White, 1 Ream (500 Sheets), Jam-Free
1 ream (500 sheets) of 8.5 x 11 white copier and printer paper for home or office use; Virgin copy paper providing professional quality results; acid-free to prevent yellowing
$6.97
Bestseller No. 2
HP Printer Paper | 8.5 x 11 Paper | Copy &Print 20 lb | 1 Ream Case - 500 Sheets| 92 Bright | FSC Certified | 200060
HP Printer Paper | 8.5 x 11 Paper | Copy &Print 20 lb | 1 Ream Case - 500 Sheets| 92 Bright | FSC Certified | 200060
Sheet size – 8.5 x 11; Thickness – 20 pounds; Brightness – 92 bright white
$6.97
Bestseller No. 3
Amazon Basics Multipurpose Copy Printer Paper, 20 lb, 8.5 x 11 Inches, 3 Reams (1,500 Sheets), 92 Bright White for Home Use
Amazon Basics Multipurpose Copy Printer Paper, 20 lb, 8.5 x 11 Inches, 3 Reams (1,500 Sheets), 92 Bright White for Home Use
Virgin copy paper providing professional quality results; acid-free to prevent yellowing
$21.96
Bestseller No. 4
Amazon Basics Multipurpose Copy Printer Paper, 20 lb, 8.5 x 11 Inches, 5 Reams (2,500 Sheets), 92 Bright White
Amazon Basics Multipurpose Copy Printer Paper, 20 lb, 8.5 x 11 Inches, 5 Reams (2,500 Sheets), 92 Bright White
Virgin copy paper providing professional quality results; acid-free to prevent yellowing
$29.14
Bestseller No. 5
Amazon Basics Multipurpose Copy Printer Paper, 20 lb, 8.5 x 11 Inches, 8 Reams (4,000 Sheets), 92 Bright White, Great for Crisp Ink Printing
Amazon Basics Multipurpose Copy Printer Paper, 20 lb, 8.5 x 11 Inches, 8 Reams (4,000 Sheets), 92 Bright White, Great for Crisp Ink Printing
Virgin copy paper providing professional quality results; acid-free to prevent yellowing
$53.19

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.