Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
Use your PDF renderer’s header feature, not ordinary HTML positioned at the top of the document. In Puppeteer, enable displayHeaderFooter, put the markup in headerTemplate, and reserve a top margin large enough for it. Other engines—wkhtmltopdf, Prince and WeasyPrint—have different APIs, so first identify the renderer and installed version that actually creates your PDF.
Choose the header method for your renderer
HTML-to-PDF is not one standard implementation. The application, framework or hosting service may wrap a browser engine or a paged-media formatter. Header syntax that works in Puppeteer should not be copied into another renderer without checking its documentation.
| Renderer | Documented header route | Best fit |
|---|---|---|
| Puppeteer | displayHeaderFooter, headerTemplate, footerTemplate, margins and page-number template classes |
Node.js applications already using Chromium |
| wkhtmltopdf | Command-line header/footer options, HTML header/footer documents and replacement placeholders | Existing wkhtmltopdf pipelines |
| Prince | CSS paged-media page-margin boxes and generated content | CSS-driven running headers, counters and content-derived strings |
| WeasyPrint | Running elements placed into page margins | Python workflows that need CSS paged-media layout |
The practical decision points are whether your header is static or based on document content, whether you need page counters, and whether your pipeline is controlled by JavaScript/API options or CSS paged-media rules.
Add a repeating header with Puppeteer
1. Confirm the code path and version
Find the function that calls page.pdf(). An application can use Puppeteer directly or through a wrapper, and options passed to a different layer may be ignored. Confirm the installed Puppeteer version and make changes where the PDF is actually generated.
#1 Best Overall
- 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
2. Enable the header and reserve space
Pass a header template and set displayHeaderFooter: true. The template is HTML, normally a small self-contained block. Set the top margin to accommodate its real height; there is no universal correct value.
await page.pdf({
path: 'output.pdf',
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: '60px', bottom: '40px' }
});
The text and measurements in this example are illustrative. Measure your actual header, account for its padding and borders, and adjust the page format and margins together. If the margin is too small, body content can overlap the header or appear to start inside it.
3. Use the built-in page placeholders
Puppeteer supports template classes such as pageNumber and totalPages. Keep these spans in the header or footer template when you need numbering. They are renderer placeholders, not values that your page’s JavaScript must calculate.
4. Remember that print CSS is the default
Puppeteer generates PDFs using the print CSS media type by default. Rules inside @media print and @page can therefore change the result from what you see in a normal browser tab. If the intended PDF should follow screen styles, select the screen media type before generating it:
Rank #2
- 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
await page.emulateMediaType('screen');
await page.pdf({
path: 'output.pdf',
displayHeaderFooter: true,
headerTemplate: '<div style="font-size:9px; width:100%; text-align:center;">Quarterly report</div>',
margin: { top: '60px', bottom: '40px' }
});
Use this only when screen styling is what you want. Otherwise leave the default print media behavior and fix the print stylesheet.
5. Keep the template self-contained
Header and footer templates are separate from the page body. Inline the essential styles and avoid assuming that your application’s page stylesheet, layout containers or JavaScript will be available inside the template. Use a fixed, predictable width and test long titles, unusual characters and different page sizes.
Make the header fit the document layout
Measure instead of guessing
Choose the paper format and orientation first, then determine the header’s rendered height at the intended font and width. Add enough top margin for the content plus breathing room. Repeat the process for the footer and bottom margin.
Check page breaks
A header that looks correct on page one can collide with content after a forced break, a large heading or a table. Inspect the first page and at least one later page. Check pages containing long titles, images, lists and tables, because these expose insufficient margins and unexpected print rules quickly.
Rank #3
- 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
Control print-only styling
Review @page, print margins, color-adjustment rules, fixed-position elements and any CSS that hides or moves content for printing. A body element with its own top padding does not replace the PDF margin reserved for a renderer-managed header.
Headers in wkhtmltopdf
wkhtmltopdf uses command-line header and footer settings rather than Puppeteer’s template options. Its usage documentation describes text headers, HTML header/footer documents and replacement placeholders. Consult the usage output for the exact options supported by your installed build, then reserve enough page space with the corresponding margin settings.
Do not paste headerTemplate, displayHeaderFooter or Puppeteer’s placeholder classes into a wkhtmltopdf command and expect them to work. The concepts are similar—renderer-owned header content, page counters and margins—but the option names and placeholder syntax are not portable.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsHeaders with Prince
Prince implements CSS paged media. Page-margin boxes and generated content can place running headers, footers and page numbers around the page area. This is useful when the header should be driven by CSS counters or document content rather than a one-off API string.
Rank #4
- 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
Build the rule for the Prince version in your deployment, define the page size and margins, and verify how running content behaves across page breaks. A CSS rule designed for Prince is not automatically supported by Chromium’s PDF output.
Headers with WeasyPrint
WeasyPrint can move HTML boxes into page margins with running elements. Its API reference also notes a limitation involving the start parameter of element(); check the installed release when your design depends on that behavior.
As with Prince, keep the page-margin CSS specific to the engine you run. Confirm the result with the exact WeasyPrint version used in production rather than relying on a browser preview.
Free tools Windows power users keep installed
One-click scans. No signup required.
Common failures and fixes
The header does not appear
- Confirm that the PDF call sets
displayHeaderFooter: true(Puppeteer). - Verify that the option reaches the renderer rather than being dropped by a wrapper.
- For command-line tools, print the installed usage help and check the header option names.
The body overlaps the header
- Increase the renderer’s top margin; body padding alone is not sufficient.
- Reduce header padding, font size or line height only after measuring the actual design.
- Check whether a page-size or orientation change increased the header’s wrapping.
The PDF looks different from the web page
- Remember that Puppeteer uses print media by default.
- Inspect
@media printand@pagerules. - If screen styling is required, call
page.emulateMediaType('screen')beforepage.pdf().
Page numbers are blank
- Use the renderer’s documented placeholders, such as
pageNumberandtotalPagesin Puppeteer. - Do not expect those classes to work in wkhtmltopdf, Prince or WeasyPrint; each engine has its own mechanism.
The header works locally but not in production
- Compare renderer and browser versions, launch flags, fonts and page dimensions.
- Check whether production uses a wrapper or a different PDF engine.
- Save a representative PDF artifact and compare the first and later pages, not only a screenshot of the browser view.
Images or fonts are missing
- Use absolute, reachable asset URLs or embed required assets according to your renderer’s rules.
- Wait until the page has loaded the resources your header depends on before creating the PDF.
- Test in the same network and runtime environment as production.
Validate before shipping
- Identify the renderer and installed version.
- Generate a PDF with a short header and a visible page counter.
- Test the first page, a later page, a page break, a long title and a table or image.
- Inspect print CSS, page size, orientation and all four margins.
- Increase margins until no body content touches the header or footer.
- Automate a visual or text-level check in the same environment used for deployment.
Or skip the browser setup
If you need clean website captures or PDFs without maintaining a browser-rendering pipeline, ScreenshotNeo provides a GET-based screenshot API and MCP server. It accepts cookie and consent banners like a visitor, then removes more than 60 known consent platforms, newsletter popups and chat widgets before capture; each step can be switched off. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads and cache hits are not billed, and the response identifies the page verdict and billing status in X-Page-Verdict and X-Billed headers.
For API details, see the ScreenshotNeo documentation. This call returns a WebP capture of the target page:
Best Value
- Made in USA: HP Papers is sourced from renewable forest resources and has achieved production with 0% deforestation in North America.
- Optimized for HP technology: All HP Papers provide premium performance on HP equipment, as well as on all other printer and copier equipment.
- Perfect everyday office paper: Superior quality, reliability, and dependability for high-volume printing at home, at school and in the office. Perfect for everyday black and white printing.
- Certified sustainable: HP Office20 20lb printer paper is Forest Stewardship Council (FSC) certified and contributes toward satisfying credit MR1 under LEED (Leadership in Energy and Environmental Design).
- ColorLok technology printing paper: ColorLok technology provides more vivid colors, bolder blacks and faster drying.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
Equivalent 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)
Equivalent 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 PDF capture options, custom CSS and JavaScript, waiting rules, device and viewport controls, headers and cookies, geolocation and timezone settings, signed links, asynchronous jobs and bulk capture. Its MCP server exposes take_screenshot, get_page_info and capture_pdf for Claude, Cursor and other MCP clients. The Free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account to try it.
FAQ
Can I add a header using only HTML and CSS?
Only when the renderer supports the relevant paged-media behavior. For reliable repeating headers, use the renderer’s documented API or paged-media feature instead of a normal top-of-document element.
Why is my header visible in the browser but missing from the PDF?
Browser display and PDF generation are separate paths. The PDF call may not enable headers, may use print CSS, or may be running through a different renderer than the page preview.
What margin should I use?
There is no universal value. Set it from the real rendered header height, then inspect generated pages for collisions.
Can Puppeteer header templates use my page’s CSS?
Do not assume they can. Put essential header styling inline and treat the template as a separate document fragment.
Quick Recap
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.

