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.

To make a Puppeteer PDF include the page’s intended design, choose the right media type, enable CSS backgrounds, and wait for the page’s actual render-ready state before calling page.pdf(). Puppeteer uses print CSS by default and does not print CSS backgrounds unless you set printBackground: true. Neither setting guarantees that asynchronously loaded foreground images or client-rendered content are ready.

Use the right media type and PDF options

Page.pdf() renders with the print CSS media type by default. That is usually appropriate for a document designed for printing. If the PDF should look like the on-screen page instead, call page.emulateMediaType('screen') before generating it.

CSS background colors and images are a separate setting: printBackground defaults to false. Turn it on when those graphics are part of the output. It does not control ordinary foreground <img> elements or wait for them to load.

What you want What to do
Print-specific layout Leave the default print media type in place and use your page’s print CSS.
Screen-oriented layout Call page.emulateMediaType('screen') before page.pdf().
CSS background colors or images Set printBackground: true.
Explicit paper dimensions or page sizing Review format, width, height, preferCSSPageSize, margins, and scale together.

See the Puppeteer PDFOptions reference and Page API for the documented controls. The referenced current API version is Puppeteer 25.12.0; rendering can vary with the deployed browser, so record both Puppeteer and browser versions when reproducing a production issue.

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.

Wait for images and application rendering

Navigation’s waitUntil option can wait for network activity to become quiet, but network quiet is not proof that every image is visible or that client-side rendering has finished. Lazy-loaded images may not be requested until they approach the viewport; an application may also reveal content after hydration or another asynchronous step.

Use a condition that corresponds to the page’s own behavior: for example, an application-provided ready flag, a known selector appearing, or a check that relevant image elements have completed loading. Puppeteer documents waitForNetworkIdle() with a default idle time of 500 ms; the networkidle0 and networkidle2 lifecycle conditions use a 500 ms quiet period with zero or two connections, respectively. Those thresholds describe network activity, not application completion.

Puppeteer waits for fonts by default, and the current PDF options document waitForFonts: true as the default. Keeping it enabled is sensible when the correct typeface matters; if text still falls back, inspect the font requests and the page’s font-loading state.

Generate a PDF with Puppeteer

This Node.js example uses print styling, enables backgrounds, and waits for a page-specific readiness signal. Replace the example URL and ready condition with ones appropriate to your application.

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

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

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

    // Replace this selector with a signal your application exposes
    // only after the content and images needed for the PDF are ready.
    await page.waitForSelector('[data-pdf-ready="true"]');

    // Keep this line only if the PDF should use screen media rules.
    // For a print-oriented PDF, leave print media as the default.
    // await page.emulateMediaType('screen');

    await page.pdf({
      path: 'output.pdf',
      printBackground: true,
      waitForFonts: true,
      format: 'A4',
      preferCSSPageSize: true,
    });
  } finally {
    await browser.close();
  }
})();

If the page has no application-level ready selector, remove waitForSelector and substitute a condition the page actually supports. Do not treat networkidle2 alone as a guarantee that lazy images or later rendering work are complete. For screen appearance, uncomment the media emulation call and place it before page.pdf().

Control print colors and page sizing

Even with backgrounds enabled, print rendering can alter colors. Puppeteer’s Page API points to the CSS property -webkit-print-color-adjust when exact colors are needed. Confirm the effect in the browser version used for production, since the rendered PDF is produced by that browser.

For unexpected page dimensions, check the PDF options as a group rather than changing only one value: format, width, height, preferCSSPageSize, margins, and scale can affect the result. The PDFOptions reference describes these settings.

Troubleshoot missing images or styles

  • Layout differs from the browser: Check whether a @media print rule is active. If the PDF is meant to follow screen styles, emulate screen media before PDF generation.
  • Colored blocks or background images disappear: Set printBackground: true. This option does not wait for foreground images.
  • Foreground images are missing: Inspect their network requests and DOM state, and check lazy-loading, hydration, and other client-side rendering behavior. Wait for a relevant application-ready condition.
  • Fonts look wrong: Verify that font resources load and that the page reaches the expected font state. waitForFonts is documented as true by default.
  • Colors look faded or altered: Check print CSS and consider -webkit-print-color-adjust; verify the result using the browser version deployed in production.
  • Pages are cropped or scaled unexpectedly: Review format, width, height, preferCSSPageSize, margins, and scale.
  • Output varies between environments: Record Puppeteer and browser versions; the current official API references identify Puppeteer 25.12.0, and its changelog dates that release to 2026-09-23.
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 managing Puppeteer, ScreenshotNeo provides a website screenshot API and MCP server. Its API accepts one GET request with a URL and returns an image or PDF; see the ScreenshotNeo documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
The SQL Programming Language: .
  • Used Book in Good Condition
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo removes cookie banners, newsletter popups, and chat widgets before the shot. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed. Its MCP server lets AI agents use take_screenshot, get_page_info, and capture_pdf. The Free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 screenshots.

Sign up for 1,000 free screenshots a month, with no card required.

Frequently Asked Questions

Does Puppeteer include CSS backgrounds in PDFs by default?

No. Set printBackground: true in page.pdf() when background graphics should appear.

Does networkidle2 guarantee that every image is in the PDF?

No. It indicates a period of network quiet, not completion of all lazy loading or application-side rendering. Await a page-specific ready condition when needed.

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.