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

Fix a misrendered Chrome Headless PDF by reproducing it with the exact production HTML, CSS, fonts, Chrome/Chromium build, Puppeteer version, operating system, and PDF options. Then diagnose in this order: print versus screen media, page geometry and scaling, backgrounds and color adjustment, font and application readiness, browser headers and footers, and finally runtime differences. There is no universal fix because “incorrect” can mean different page dimensions, missing colors, substituted fonts, clipped content, unexpected breaks, or a page captured before JavaScript finished.

1. Preserve a minimal, versioned reproducer

Before changing CSS, save the exact URL or HTML, all stylesheets, font files, data used to populate the page, and the command or script that creates the PDF. Record:

  • Chrome or Chromium version and executable path.
  • Puppeteer version, Node.js version, operating system, and container image.
  • Every page.pdf() option, including defaults you did not set.
  • Installed fonts and whether network requests are allowed.
  • The PDF produced in the failing environment and a reference PDF from desktop Chrome, if one exists.

Change one variable at a time. A historical Puppeteer issue reported a page-size discrepancy in Puppeteer 1.2.0 on macOS 10.13.3 compared with Chrome 65; that report shows why environment comparison matters, not that current releases share a universal defect.

2. Check print media before changing layout

page.pdf() generates a PDF using the print CSS media type by default. Rules inside @media print, print-specific inherited styles, and @page can therefore produce a layout unlike the screen.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

Use print CSS intentionally

Keep print rules when the PDF is meant to be a document. Inspect rules that set display:none, widths, colors, overflow, position, or page breaks. Also inspect styles inherited from ancestors; a print rule on a wrapper can make a child appear clipped even when the child’s own CSS looks correct.

Use screen styles when that is the requirement

Call page.emulateMediaType('screen') immediately before generating the PDF:

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

This does not make a PDF identical to a screenshot: pagination, paper dimensions, margins, and print color handling still apply.

3. Make page size, orientation, margins, and scale agree

Paper geometry can be declared in CSS and in Puppeteer. A conflict is a common cause of apparent shrinking, unexpected page breaks, and content that is cut off.

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.

Choose one source of truth

CSS can declare a size:

@page {
  size: A4 portrait;
  margin: 12mm;
}

Puppeteer can instead select a named format or explicit dimensions:

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
await page.pdf({
  format: 'A4',
  landscape: false,
  margin: { top: '12mm', right: '12mm', bottom: '12mm', left: '12mm' },
  scale: 1,
  printBackground: true
});

preferCSSPageSize determines precedence. Its documented default is false, so Puppeteer’s chosen paper size is normally used and the content is scaled to fit it. Set it to true when the CSS @page size must win:

await page.pdf({
  preferCSSPageSize: true,
  printBackground: true
});

Do not compensate for a size mismatch by randomly changing widths. Compare, together, @page size, format or width/height, landscape, margins, and scale. Remove one competing declaration if possible. Remember that explicit margins consume printable area; a fixed-width child wider than the remaining area can overflow even when the paper size is correct.

4. Restore backgrounds and control print colors

Puppeteer’s printBackground option defaults to false. Set it to true for background fills, gradients, and background images:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
await page.pdf({ path: 'output.pdf', printBackground: true });

Chrome also modifies colors for printing by default. When exact on-screen colors are required, add print color adjustment in the stylesheet:

html {
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

Use this deliberately: a color that looks good on a backlit display may be too dark or consume substantial ink on paper. Verify the result in the PDF viewer used by your recipients.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

5. Wait for fonts and dynamic content

Fonts

Puppeteer’s waitForFonts PDF option defaults to true in current documentation and waits for document.fonts.ready. That only helps if the requested font can actually load. Check the browser console and network log for failed font URLs, CORS errors, incorrect MIME types, and a font family name that does not match the CSS. In a container, install the same font files or package used in the reference environment.

Application state

Font readiness does not mean that your application has finished rendering. Wait for a selector or explicit application state after navigation:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
await page.goto('https://example.com/invoice/42', { waitUntil: 'networkidle0' });
await page.waitForSelector('[data-pdf-ready]', { visible: true });
await page.evaluate(() => document.fonts.ready);
await page.pdf({ path: 'invoice.pdf', printBackground: true, waitForFonts: true });

Use an application-specific readiness marker when data arrives after the initial network becomes idle. For animations, clocks, or delayed scripts, make the page deterministic rather than relying on an arbitrary sleep.

Chrome CLI timing controls

When using Chrome directly, --timeout bounds capture timing and --virtual-time-budget gives time-dependent JavaScript a controlled virtual interval. Neither value guarantees that a particular application is ready; choose a value based on an observable readiness condition where possible.

6. Remove unexpected headers and footers

Chrome can add a date/time header and a footer containing the URL and page number. The current Chrome CLI flag is --no-pdf-header-footer:

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
google-chrome --headless --no-sandbox 
  --no-pdf-header-footer 
  --print-to-pdf=output.pdf 
  https://example.com

Older Chrome versions used --print-to-pdf-no-header. If the current spelling is rejected, check the installed Chrome version and its command-line documentation rather than silently accepting browser furniture.

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.

In Puppeteer, set displayHeaderFooter: false (the default in the PDF options documented for current versions). If you need custom material, set it to true and supply headerTemplate and footerTemplate; otherwise disable it explicitly so a version change cannot surprise you.

7. A complete Puppeteer baseline

This Node.js script provides a controlled starting point. Replace the URL and readiness selector with values from your application.

import puppeteer from 'puppeteer';

const browser = await puppeteer.launch({
  headless: true,
  // Supply executablePath here when production uses a pinned Chrome build.
});

try {
  const page = await browser.newPage();
  await page.setViewport({ width: 1280, height: 900, deviceScaleFactor: 1 });
  await page.goto('https://example.com', {
    waitUntil: 'networkidle0',
    timeout: 90000
  });
  await page.waitForSelector('[data-pdf-ready]', {
    visible: true,
    timeout: 30000
  });
  await page.evaluate(() => document.fonts.ready);

  // Omit this line when the PDF should use print CSS.
  await page.emulateMediaType('screen');

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

For a print-CSS document, remove the emulateMediaType('screen') call. For a CSS-sized document, use preferCSSPageSize: true and avoid simultaneously imposing a contradictory format.

8. Troubleshoot by symptom

Symptom Likely cause Check or fix
Screen and PDF layouts differ Print media rules are active Inspect @media print; emulate screen only if screen styling is intended.
Pages are the wrong size or content is scaled CSS and Puppeteer geometry conflict Compare @page, format/width/height, margins, orientation, scale, and preferCSSPageSize.
Colors, gradients, or images disappear Background printing is disabled Set printBackground: true; add print color adjustment when exact colors are required.
Text wraps differently or uses a fallback font Font failed to load or was captured too early Inspect font requests, install identical fonts, and await document.fonts.ready.
Charts, totals, or images are missing Application JavaScript has not reached its ready state Wait for a specific selector/state, not only a fixed delay.
Date, URL, or page numbers appear PDF header/footer is enabled Disable displayHeaderFooter or use the Chrome flag appropriate to your version.
CLI flag is unknown Flag spelling differs by Chrome release Check the installed build; older releases used --print-to-pdf-no-header.
Only production fails Runtime mismatch Compare Chrome build, Puppeteer, OS/container, fonts, executable path, and all options.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

9. Reliability and performance practices

  • Pin the Chrome/Chromium build and Puppeteer version in CI so a browser update is a deliberate change.
  • Log the effective URL, navigation errors, console errors, failed requests, readiness selector, and PDF options for each job.
  • Use a stable viewport and device scale factor; otherwise responsive breakpoints can change the layout.
  • Prefer deterministic data, disabled animations, and an explicit ready marker over long arbitrary sleeps.
  • Set navigation and selector timeouts that match your application, then fail with a useful diagnostic rather than emitting a partial PDF.
  • Keep a small visual regression set covering long text, images, tables, page breaks, and non-Latin fonts.

Or skip the browser setup

ScreenshotNeo provides a website screenshot API and MCP server; its capture endpoint can also return a PDF. One GET request is enough:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo documentation for PDF parameters, viewport and device settings, waits, CSS/JavaScript, and other options. In 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)

In 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 accepts cookie and consent banners as a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each cleanup step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server exposes take_screenshot, get_page_info, and capture_pdf to Claude, Cursor, and other MCP clients. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots, with every feature on every plan.

Create a free ScreenshotNeo account to try it without a card.

FAQ

Should I always emulate screen media?

No. Use screen media only when the PDF is intended to match the screen. Print media is the default and is usually the correct choice for a print-oriented document.

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

Why does setting A4 still produce unexpected breaks?

A4 can be overridden by CSS or interact with margins, scale, orientation, and fixed-width content. Decide whether CSS or Puppeteer owns page size and make the other settings consistent.

Does waiting for fonts guarantee correct text layout?

No. It waits for font readiness, but the requested font may be unavailable or fail to load. Verify the actual font files and runtime environment.

Frequently Asked Questions

Can a historical Puppeteer issue explain my current PDF bug?

It can suggest checking environment differences, but a report from an older Puppeteer and Chrome release is not proof of a defect in current versions.

What is the safest first change when a PDF is blank?

Capture console and request errors, confirm the navigation URL, and wait for an application-specific ready selector before changing layout CSS.

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.