Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk5 min

How to Include All Images and Styles in Puppeteer PDF Output

Make Puppeteer PDFs match the intended page by choosing print or screen media, enabling CSS backgrounds, and waiting for images and application rendering.

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 styles and images you expect, choose the right media type, enable CSS backgrounds, and wait for the page’s actual render-ready state. page.pdf() uses print CSS by default, and its printBackground option defaults to false. Neither option, on its own, guarantees that asynchronously loaded or lazy-loaded foreground images are ready.

Use the media type that matches the PDF you want

Puppeteer’s Page.pdf() renders with the print CSS media type by default. That is appropriate when the PDF should follow print-specific rules such as @media print. If instead the PDF should resemble the page as it appears on screen, switch to screen media before generating it:

As an Amazon Associate I earn from qualifying purchases.

await page.emulateMediaType('screen');

Make this choice before page.pdf(). Switching media can change more than colors: print styles may hide navigation, alter layout, or change element visibility. The Puppeteer Page API documents PDF rendering and print color behavior.

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

Enable CSS background graphics

Set printBackground: true to include CSS background graphics such as background colors and images. The option defaults to false. It controls backgrounds; it is not a general switch for loading ordinary foreground <img> elements.

await page.pdf({
  path: 'output.pdf',
  printBackground: true,
});

For colors that change during print rendering, the Page API points to the CSS property -webkit-print-color-adjust. For example, a page’s print stylesheet can use -webkit-print-color-adjust: exact when preserving specified colors is important. Check the rendered result in the browser version used in production; print CSS and browser rendering both affect the output.

Wait for fonts, images, and application rendering

Fonts

Puppeteer’s PDF options document waitForFonts: true as the default, and its PDF guide says Page.pdf() waits for fonts by default. You can set it explicitly to make the intended behavior clear. If text still uses a fallback typeface, check that the font requests succeed and that the page’s font-loading logic has completed.

Foreground and lazy-loaded images

For missing foreground images, inspect the image elements, their request status, and whether the application only loads them after scrolling or another interaction. A quiet network is not proof that a lazy image was requested, that client-side hydration finished, or that every component has rendered. Wait for a meaningful condition from the page or application when those behaviors apply.

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

Network idle and app-ready signals

You can use navigation lifecycle events or page.waitForNetworkIdle() to wait for network activity to settle. Puppeteer defines networkidle0 and networkidle2 as a 500 ms quiet period with no more than zero or two active connections, respectively. waitForNetworkIdle() documents a default idle time of 500 ms. These are network conditions, not guarantees that site-specific rendering is complete.

If your application exposes a documented ready flag, selector, or other completion condition, await it after navigation and before producing the PDF. Do not substitute a fixed delay for a reliable signal unless the application has no better condition and the delay is appropriate to your workload.

A practical Puppeteer sequence

This example uses screen media; remove the media switch to retain Puppeteer’s default print media. Replace the illustrative app-ready condition with one your page actually provides, or remove it if no such condition applies.

import puppeteer from 'puppeteer';

const browser = await puppeteer.launch();
try {
  const page = await browser.newPage();
  await page.goto('https://example.com', { waitUntil: 'networkidle2' });

  // Use this only when the PDF should follow screen CSS instead of print CSS.
  await page.emulateMediaType('screen');

  // Replace with a real condition exposed by your application, if applicable.
  // await page.waitForFunction(() => window.appRenderComplete === true);

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

For print-oriented output, omit emulateMediaType('screen') and provide print styles. The Puppeteer PDF generation guide recommends Page.pdf() for PDF printing.

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

Set page dimensions and color behavior deliberately

When the PDF’s paper size, margins, or scale are wrong, review the relevant PDF options rather than changing image-loading waits. Puppeteer documents format, width, height, margin, scale, and preferCSSPageSize. Use explicit dimensions when the PDF needs a specific paper size; consider preferCSSPageSize when the page’s @page CSS rule should determine the size.

Best Value
The SQL Programming Language: .
  • Used Book in Good Condition
Decision Use
Print CSS or screen CSS Print is the default. Call page.emulateMediaType('screen') before PDF generation when screen rules should apply.
Include CSS backgrounds Set printBackground: true; the documented default is false.
Wait for network quiet or application readiness Use navigation lifecycle events or waitForNetworkIdle() for network inactivity; use an application-specific condition when rendering continues after requests settle.
Set PDF dimensions Review format, width, height, margins, scale, and preferCSSPageSize against the page’s CSS and output requirements.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot missing images or styles

  • Layout differs from the browser: check whether print CSS is active. If the PDF should use screen rules, call emulateMediaType('screen') before page.pdf().
  • Colored areas or background images are absent: set printBackground: true.
  • Foreground images are absent: inspect their network requests and DOM state. Check lazy-loading triggers, hydration, and application rendering; network idle alone does not establish that the images were loaded.
  • Text uses the wrong font: verify font requests and page font-loading behavior. Puppeteer’s documented default is to wait for fonts, but failed font resources can still produce fallback text.
  • Print colors look different: review print CSS and consider -webkit-print-color-adjust; validate with the deployed browser version.
  • Page size or scaling is wrong: check format, width, height, preferCSSPageSize, margins, and scale.
  • The output is intermittently incomplete: replace assumptions based only on a network-idle event or arbitrary delay with a page-specific render-ready condition where possible.

Record versions when reproducing a PDF issue

The official Puppeteer API references identify version 25.12.0, dated 2026-09-23 in the Puppeteer changelog; that release records a roll to Chrome 154.0.8037.57. Rendering can depend on the browser/runtime, so record your deployed Puppeteer and browser versions when comparing output or investigating a regression.

Or skip the browser setup

If you need a website screenshot rather than a Puppeteer-generated PDF, ScreenshotNeo provides a screenshot API and MCP server. Its PDF option is available through the same service. The API accepts a URL and returns a PNG, JPEG, WebP, or PDF; see the ScreenshotNeo API documentation.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

ScreenshotNeo removes cookie/consent banners, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks/CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, with response headers indicating the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots.

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

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

Frequently Asked Questions

Does printBackground: true make Puppeteer wait for every image?

No. It enables CSS background graphics. Foreground image loading and application rendering need to be checked and awaited separately.

Which Puppeteer version should I report when a PDF looks different?

Record the Puppeteer and browser/runtime versions actually deployed; rendering behavior can depend on both.

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.

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

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.