Recommended Free Tools
To generate PDFs from HTML automatically, use a headless browser such as Puppeteer or Playwright when your document depends on browser-rendered pages, or a paged-media renderer such as Prince when CSS-driven page layout, numbering, and running headers or footers are central. Both Puppeteer and Playwright generate PDFs using print CSS by default. Choose by testing your real HTML, fonts, page rules, and deployment environment; the available documentation does not establish a universal winner for speed, reliability, or cost.
Choose the right kind of PDF renderer
The main decision is whether you need to print a web page as a browser sees it or lay out a document with page-specific publishing rules. These approaches overlap, but they are not interchangeable in every workflow.
| Approach | Best starting point | Relevant documented capabilities |
|---|---|---|
| Browser automation | HTML already rendered in Chromium, including application pages and web content | Puppeteer and Playwright expose PDF generation through a browser page. Both use print CSS media by default. Playwright documents paper formats, margins, page ranges, headers and footers, and a tagged-PDF option. |
| Paged-media renderer | Document-oriented HTML/XML where page layout and page furniture are important | Prince converts HTML and XML to PDF using CSS and documents paged-media features such as page numbering and headers and footers. |
These distinctions describe documented features, not a comparative performance result. Benchmark representative documents in the environment where you intend to run them before making a production choice.
Generate a PDF with Puppeteer
Puppeteer’s Page.pdf() generates a PDF using the print CSS media type. If you need the screen stylesheet instead, call page.emulateMediaType('screen') before creating the PDF. Puppeteer also notes that print output may alter colors; use the CSS property -webkit-print-color-adjust when you need to control color adjustment. See the Puppeteer Page.pdf() API documentation and the PDF generation guide.
#1 Best Overall
Basic Node.js example
Install Puppeteer in a Node.js project, then save the following as an ES module, for example generate.mjs. Replace the URL with a page you are authorized to capture.
import puppeteer from 'puppeteer';
const browser = await puppeteer.launch();
try {
const page = await browser.newPage();
await page.goto('https://example.com', { waitUntil: 'networkidle0' });
await page.pdf({ path: 'page.pdf', format: 'A4', printBackground: true });
} finally {
await browser.close();
}
The example waits for network activity to settle before printing, but that is not a guarantee that every application-specific image or late-loaded component is ready. If a page has a known readiness condition, wait for that condition explicitly before calling page.pdf(). The Puppeteer guide says PDF generation waits for fonts to load by default; it does not promise that every external asset or application interaction has completed.
Use screen CSS instead of print CSS
await page.emulateMediaType('screen');
await page.pdf({ path: 'screen-styled.pdf', printBackground: true });
Use this only when the screen styling is actually the intended output. Print styles often remove navigation, adjust widths, or add page-specific rules for more readable paper output.
Generate a PDF with Playwright
Playwright’s page.pdf() also uses print CSS media. Its API exposes paper formats and units, margins, page ranges, header and footer templates, background printing, CSS page-size preference, and a tagged-PDF option. The documented default for tagged is false. A tagged option alone is not proof that a PDF meets an accessibility standard. Refer to Microsoft’s Playwright Page API.
Basic Node.js example
Install Playwright and the browser it will run, then use this ES module example. Adjust the format, URL, or output file to your use case.
import { chromium } from 'playwright';
const browser = await chromium.launch();
try {
const page = await browser.newPage();
await page.goto('https://example.com', { waitUntil: 'networkidle' });
await page.pdf({
path: 'page.pdf',
format: 'A4',
printBackground: true,
margin: { top: '20mm', right: '15mm', bottom: '20mm', left: '15mm' }
});
} finally {
await browser.close();
}
Playwright’s PDF API supports additional controls when a basic page export is not enough. Check the API documentation for the exact accepted option names and behavior for the version you install.
- Paper and units: choose a documented paper format or dimensions and set margins in supported units.
- Page-size CSS: use
preferCSSPageSizewhen the document’s@pagerules should take precedence over the PDF format setting. - Page ranges: request selected ranges when exporting only part of a longer document.
- Headers and footers: supply templates for repeated page furniture where appropriate.
- Tagged output: enable the documented tagged-PDF option if it fits your needs, then independently validate the result against the accessibility requirements that apply to your project.
Use CSS page rules and control pagination
Browser-based PDF generation applies print behavior, so the document should be designed for pages rather than only for a scrolling viewport. A print stylesheet can set page margins, avoid splitting important blocks, and hide elements that belong only in an interactive interface.
@media print {
.site-navigation, .cookie-controls { display: none; }
h1, h2 { break-after: avoid-page; }
.invoice-line, .summary-card { break-inside: avoid; }
}
@page {
size: A4;
margin: 18mm 15mm;
}
CSS page rules and renderer options can interact. In Playwright, test whether preferCSSPageSize is appropriate for your document rather than assuming that the stylesheet’s page size wins. Preview representative output for overflow, clipped tables, orphaned headings, and unexpected blank pages.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Scan for outdated or missing drivers - takes under a minute3Clear out junk files and repair common Windows errorsHeaders, footers, and page numbers
For browser automation, use the renderer’s documented header/footer support and test the actual template output, including page numbering and margins. Prince is worth evaluating when page-oriented features such as numbering and running headers and footers are a primary requirement; its user guide documents CSS-based conversion and paged-media features. Documentation of a feature does not guarantee that a particular template will render as you expect, so build a small representative document before committing to a renderer.
Or skip the browser setup
If the job is to capture a web page as a PDF rather than build a document pipeline around your own browser, ScreenshotNeo provides a website screenshot API and MCP server. Its PDF endpoint accepts a URL in one GET request; the options include paper size, margins, landscape, and page ranges. See the ScreenshotNeo API documentation for request details.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
For PDF output, set the documented PDF output option and any required paper or margin parameters from the API documentation. This example illustrates the one-call URL capture pattern; do not assume a screenshot image extension is a PDF filename. ScreenshotNeo removes cookie/consent banners, newsletter popups, and chat widgets before capture, with each step configurable. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers report the page verdict and billing status. Its MCP server includes take_screenshot, get_page_info, and capture_pdf for AI agents using Claude, Cursor, or another MCP client. The free plan includes 1,000 shots per month without a card; paid plans start at $5 for 3,000 shots. Sign up free for 1,000 screenshots a month, with no card required.
Validate the output before automating at scale
A successful API call or browser method only establishes that a PDF was produced; it does not establish that the result is complete or suitable. Test with the kinds of documents your workflow actually generates.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minute- Compare screen and print media output, especially if stylesheets change layout substantially.
- Check paper size, margins, page breaks, and whether
@pagerules or API settings control the result. - Inspect background colors, images, custom fonts, and other assets in the generated file.
- Check repeated headers and footers, page numbers, and page ranges on a multi-page document.
- Review tagged output separately against the applicable accessibility requirement.
- Measure throughput, failure rates, resource use, and operating cost using representative documents and the intended runtime.
The cited product documentation does not provide a like-for-like benchmark that establishes which renderer is fastest, most reliable, or least costly. Those results depend on document complexity and deployment conditions, so measure them in your own workload rather than extrapolating from a basic example.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Troubleshoot common PDF-generation problems
The PDF layout does not match the browser window
PDF methods use print CSS by default in Puppeteer and Playwright. Check the print stylesheet and test screen media emulation only if screen styling is intended. Print layout may change widths, colors, and visibility compared with the interactive page.
Background colors or images are missing
Enable background printing where supported, then inspect print-specific color rules. Puppeteer notes that print output may modify colors and points to -webkit-print-color-adjust for exact color handling. Test the final PDF rather than relying on the browser preview.
Fonts or images are absent
Confirm that the page’s assets have loaded before generating the PDF. Puppeteer waits for fonts by default during Page.pdf(), but its guide does not guarantee readiness for every external image or app-driven resource. Add a wait for a meaningful page condition and validate the output.
Free tools Windows power users keep installed
One-click scans. No signup required.
Rank #4
Page size or margins are unexpected
Review both the PDF call options and the document’s @page CSS. With Playwright, decide whether preferCSSPageSize should let CSS page size take precedence. Verify the result with a document containing enough content to span multiple pages.
Headers, footers, or page numbers do not appear
Check that you are using the chosen renderer’s documented header/footer or paged-media mechanism, and make sure the page margins leave room for the repeated content. Prince documents page-oriented CSS features; Playwright documents header/footer templates. Confirm behavior in the version and configuration you deploy.
The PDF exists but is not accessible enough
Do not treat tagged output as a conformance certificate. Playwright exposes a tagged-PDF option, documented as false by default, but the cited API does not establish compliance with a particular standard. Inspect and validate the generated file against your project’s actual accessibility requirement.
FAQ
Does Puppeteer generate PDFs from print or screen CSS?
Print CSS by default. Call page.emulateMediaType('screen') before page.pdf() when screen media is intended.
Does Playwright support tagged PDFs?
Yes. Its Page API documents a tagged-PDF option, whose documented default is false. That option is not, by itself, evidence of accessibility-standard conformance.
Is Prince a browser automation library?
No. Prince describes itself as an HTML/XML-to-PDF application that applies CSS, with documentation for paged-media features such as numbering and page headers and footers.
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.

