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

To test what readers will see in a Puppeteer-generated PDF, generate the PDF with the intended print settings, render its pages to images, and compare those images with approved baselines. A screenshot of the webpage is not a screenshot of the PDF: page.pdf() generates a document using print CSS, while page.screenshot() captures the browser page.

Why a webpage screenshot is not enough

Puppeteer’s page.pdf() generates a PDF using the print CSS media type by default. Its page.screenshot() method captures the browser page instead. That screenshot can help test a web interface, but it does not show how the generated PDF’s pages actually break, paginate, or render. See the Page.pdf() API and Puppeteer’s screenshots guide.

For a PDF visual regression test, retain the generated PDF, render each PDF page to an image with a PDF renderer, and compare those images with versioned, approved baselines. The PDF-to-image step is part of the testing workflow; Puppeteer documents PDF generation and browser-page screenshots, not a built-in PDF visual-diff pipeline.

Build a repeatable PDF test

1. Make the page state deterministic

Use a known route, fixed test data, and a stable application state. Where practical, control changing content and external dependencies that can alter the output. Wait for the condition that means your application is ready—for example, a known selector or an application-specific signal—rather than assuming navigation alone means the page is complete.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Freestyle 5 Books of Freestyle Self Testing Log Book Total 5 Books
  • The FreeStyle log book includes sections for: Lunch, Dinner, Bedtime, Night
  • Comments for each day of the week
  • Log Book Dimensions L=4.25" x W=3.12" x H=0.12"
  • Contains 5 book

Puppeteer’s PDF guide uses network idle in an example, but that is only one possible wait condition; it does not establish that every application is ready when network activity subsides. Fonts are a special case: the PDF generation guide says that PDF generation waits for fonts by default. Images, application data, and other asynchronous content still need an appropriate readiness strategy.

2. Generate the PDF under the intended media type

For a document designed for print, leave print media active. If the product is specifically meant to generate a PDF using screen styles, call page.emulateMediaType('screen') before page.pdf(). Puppeteer documents print, screen, and null as supported values for page.emulateMediaType(). Choose the mode that matches the product’s intended output, not whichever makes a test pass.

3. Set the output options explicitly

Use the same paper geometry and rendering options in every run. The PDFOptions API documents these relevant choices:

  • format, or width and height, for page dimensions. When format is provided, it takes priority over width and height.
  • margin for page margins; set the values to match the intended output.
  • landscape for orientation and scale for content scaling.
  • pageRanges when the test should generate only particular pages.
  • preferCSSPageSize to give a CSS @page size priority. If it is not enabled, Puppeteer scales content to fit the paper size.
  • printBackground when backgrounds are part of the intended output. Its documented default is false.

These defaults and behaviors are documented on Puppeteer’s current documentation pages; the exact Git revision for the documentation consulted is not established here. Record the Puppeteer and browser versions used by your test environment so changes in the rendering stack can be investigated.

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.

Runnable Node.js example: produce a PDF test artifact

Install Puppeteer in your project, set TEST_URL to a route with stable test data, and save this as generate-pdf.mjs. The readiness selector is an example: replace it with a condition your application sets only when the content for the PDF is ready.

import puppeteer from 'puppeteer';

const url = process.env.TEST_URL;
if (!url) {
  throw new Error('Set TEST_URL to the page to render');
}

const browser = await puppeteer.launch();
try {
  const page = await browser.newPage();
  await page.goto(url, { waitUntil: 'networkidle0' });
  await page.waitForSelector('[data-pdf-ready="true"]');

  // Use this only when the intended PDF output uses screen CSS.
  // For the usual print-CSS PDF, leave this line commented out.
  // await page.emulateMediaType('screen');

  await page.pdf({
    path: 'output.pdf',
    format: 'A4',
    landscape: false,
    margin: {
      top: '12mm',
      right: '12mm',
      bottom: '12mm',
      left: '12mm'
    },
    scale: 1,
    printBackground: true,
    preferCSSPageSize: true
  });
} finally {
  await browser.close();
}

The network-idle wait above is not a substitute for the application-specific readiness check. If your app has no data-pdf-ready marker, replace that wait with a selector or signal that accurately reflects completed data and content. Keep the output options aligned with your product contract; for example, do not enable background printing if backgrounds are not supposed to appear in the PDF.

4. Render and compare the PDF pages

Pass output.pdf to a suitable PDF renderer to produce an image for each page. Compare those images with baselines generated under the same page geometry and rendering conditions. Review differences for pagination changes, clipping, unexpected page breaks, missing images, font substitution, and blank pages.

Puppeteer’s screenshot API remains useful for separate checks of the source page or a particular element; it is not the PDF-page rendering step. The Page.screenshot() API also documents screenshot behavior and concurrency considerations. Puppeteer’s overview describes it as a JavaScript library for automating Chrome and Firefox.

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

Pixel diffs can be paired with structural assertions—such as page count, extracted text, links, or document metadata—to help distinguish a visual change from a content or pagination change. The cited Puppeteer documentation does not prescribe a PDF renderer, parser, or visual-diff library, so choose and pin those tools as part of your own test environment.

Test print colors and backgrounds deliberately

PDF color output can differ from the colors seen in a normal browser screenshot. Puppeteer says PDF colors are modified for printing by default and points to -webkit-print-color-adjust when exact colors are needed. Separately, its printBackground option defaults to false; set it to true if the intended PDF includes background graphics.

The standard CSS property print-color-adjust defaults to economy, under which a user agent may alter or omit colors and backgrounds. Its exact value asks the browser to preserve the authored appearance, but MDN’s reference warns that user-agent choices and user settings take priority, so the property cannot guarantee exact output. Align the CSS and PDF options with what your application promises, then compare the resulting PDF pages. This verifies browser-generated output; it does not prove that every printer, driver, print dialog, or paper stock will produce identical physical pages.

Troubleshoot common PDF screenshot-test failures

  • The browser screenshot looks right, but the PDF does not. The screenshot and PDF are different artifacts, and the PDF uses print CSS by default. Render the generated PDF pages to images and inspect those instead of treating page.screenshot() as a PDF check.
  • Content is missing or the output changes between runs. The page may not be ready when PDF generation begins. Wait for an application-specific readiness condition for data, images, and other asynchronous content; default font waiting does not confirm that the rest of the page is ready.
  • Page size or pagination is unexpected. Check the chosen format or dimensions, margins, orientation, scale, page ranges, and preferCSSPageSize. Confirm whether the test is intended to honor the CSS @page size or fit content to the selected paper format.
  • Backgrounds or colors differ. Check whether printBackground is enabled when needed and whether print color adjustment is consistent with the output contract. CSS color-adjust settings are not a guarantee against user-agent or user-setting overrides.
  • Baselines change after an environment update. Record the Puppeteer and browser versions alongside the test artifacts. Also keep the PDF renderer and image-comparison environment consistent; visual comparisons can otherwise mix product changes with test-environment changes.
  • The PDF passes, but printed paper differs. A browser-generated PDF test does not validate every operating system’s native print path, printer driver, printer, or paper. Test those separately if physical output is part of your requirement.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

For a screenshot of a webpage, ScreenshotNeo offers a one-request screenshot API and an MCP server for AI agents. It is not a substitute for rendering the pages of a PDF generated by Puppeteer; use a PDF renderer for that visual check. To capture a webpage directly, see the ScreenshotNeo documentation:

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.
Best Value
Accent on Composers: The Music and Lives of 22 Great Composers, with Listening CD, Review/Tests, and Supplemental Materials, Comb Bound Book & Online PDF/Audio
  • Format: Comb Bound Book & Enhanced CD
  • Version: CD Kit (Book & Enhanced CD) (Includes Reproducible Student Pages)
  • Category: General Music and Classroom Publications
  • Contributors: By Jay Althouse and Judy O'Reilly
  • Pub Date: 7/2001
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo accepts cookie and consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each of those steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and responses identify the page verdict and billing status in headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month with no card.

Frequently Asked Questions

Does Puppeteer have a built-in method for comparing PDF pages with baseline images?

The cited Puppeteer documentation covers PDF generation and browser-page screenshots; it does not document a built-in PDF visual-diff pipeline.

Does this workflow verify what every printer will put on paper?

No. It checks the browser-generated PDF, not every operating system print path, driver, printer, or paper stock.

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

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.