Most “ignored” Puppeteer PDF sizes are precedence or print-layout problems, not a broken PDF writer. A PDF can be controlled by Puppeteer’s format, width, and height options, or by the page’s CSS @page rule. If both layers specify a size, you must deliberately choose which one wins. Puppeteer also renders with print media by default, applies margins, and fragments overflowing content into additional pages.
The reliable fix is to choose one page-size owner, remove conflicting declarations, set margins explicitly, wait for layout-critical assets, and inspect the result using print styles and the exact Chromium version used in deployment.
How Puppeteer decides the PDF paper size
page.pdf() generates a paged print document rather than a screenshot of the current browser viewport. Its relevant options are format, width, height, margin, landscape, and preferCSSPageSize.
The precedence rule
When format is present, it takes priority over explicit width and height. A CSS @page size normally does not replace the API paper size. Set preferCSSPageSize: true to give a CSS @page declaration priority over format, width, and height; otherwise the content is scaled to fit the API-selected paper.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchPC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11#1 Best Overall
- 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.
That produces two stable configuration patterns:
- API-owned: use a named format or dimensions, remove competing
@page { size: ... }rules, and leavepreferCSSPageSize: false. - CSS-owned: define one explicit
@pagesize and margin, setpreferCSSPageSize: true, and do not pass contradictory API dimensions.
Defaults that make a correct setting look wrong
Chrome’s underlying print protocol uses inches for paper dimensions. Its default paper is approximately 8.5 × 11 inches (Letter), with margins of about 1 cm on each side. Puppeteer’s own margin option and CSS @page margins can add another layer. A correctly sized sheet can therefore show a visible border or a smaller content area.
Use physical units such as mm, cm, or in for custom dimensions. Numeric values are accepted, but strings make the intended physical size unambiguous.
Fix 1: let Puppeteer own the size
Start with a named standard format. It removes custom-unit rounding from the diagnosis and gives you a known baseline.
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://example.com', { waitUntil: 'networkidle0' });
await page.evaluate(() => document.fonts.ready);
await page.pdf({
path: 'out.pdf',
format: 'A4',
landscape: false,
margin: {
top: '0mm',
right: '0mm',
bottom: '0mm',
left: '0mm'
},
preferCSSPageSize: false,
printBackground: true,
waitForFonts: true
});
await browser.close();
})();
For US Letter, replace format: 'A4' with format: 'Letter'. If custom paper is required, remove format entirely:
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →await page.pdf({
path: 'label.pdf',
width: '100mm',
height: '150mm',
margin: { top: '0mm', right: '0mm', bottom: '0mm', left: '0mm' },
preferCSSPageSize: false,
printBackground: true
});
Do not pass format together with custom width and height when the custom dimensions are supposed to win; format wins.
Rank #2
- 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.
Fix 2: let CSS own the size
CSS ownership is useful for invoices, labels, and layouts already designed for printed paper. Put one physical size in @page and enable CSS precedence.
@page {
size: 210mm 297mm;
margin: 0;
}
@media print {
html, body {
margin: 0;
}
}
await page.pdf({
path: 'out.pdf',
preferCSSPageSize: true,
printBackground: true,
waitForFonts: true
});
For landscape A4, use size: A4 landscape or swap the dimensions. Do not simultaneously request a contradictory API format. Keep a single @page rule where possible; multiple rules from component or third-party stylesheets make ownership difficult to audit.
Print media is not screen media
Puppeteer’s PDF method uses the print CSS media type by default. Rules under @media print can change widths, display values, visibility, overflow, and fixed heights. The viewport configured with page.setViewport() controls browser layout conditions, but it does not define PDF paper size.
To deliberately reproduce screen styling, switch media before printing:
await page.emulateMediaType('screen');
await page.pdf({ path: 'screen-styled.pdf', format: 'A4' });
To debug the normal PDF path, use await page.emulateMediaType('print') and inspect the computed styles in that state. Printed colors may also be adjusted. If exact colors matter, add:
Rank #3
- 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.
@media print {
* {
-webkit-print-color-adjust: exact;
print-color-adjust: exact;
}
}
Why borders, clipping, and extra pages remain
Margins at more than one layer
Protocol defaults, Puppeteer’s margin, and CSS @page margins can all affect the result. Set one intended margin explicitly and remove the others while diagnosing. Also check the body’s default margin and print-specific margins.
Content exceeds the printable box
Chrome fragments content whenever the content box is larger than the available page area. A one-pixel border, fractional custom dimension, transformed element, fixed height, or horizontal overflow can push a final fragment onto a new page. Temporarily remove body margins, borders, transforms, and overflow rules. Reintroduce them one at a time in a minimal document.
Late fonts and images
A PDF captured before fonts or images settle can reflow after the intended measurement, changing page breaks. Wait for navigation, then wait for fonts and critical images:
await page.goto(url, { waitUntil: 'networkidle0' });
await page.evaluate(async () => {
await document.fonts.ready;
const images = Array.from(document.images);
await Promise.all(images.map(img => {
if (img.complete) return Promise.resolve();
return new Promise(resolve => {
img.addEventListener('load', resolve, { once: true });
img.addEventListener('error', resolve, { once: true });
});
}));
});
waitForFonts is documented with a default of true in current Puppeteer, but application code still needs to ensure that asynchronous content and images have arrived.
Custom-size rounding
Historical reports describe small width or height discrepancies and repeated edge artifacts with some custom dimensions. Treat this as browser-version-sensitive rather than a universal Puppeteer rule. First reproduce with a named A4 or Letter format; if that works, compare your custom dimensions and the exact Chromium version.
Rank #4
- 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
A repeatable diagnostic procedure
- Log the final options object. Confirm whether a wrapper, helper, or environment variable adds
format, dimensions, margins, orpreferCSSPageSize. - Search every loaded stylesheet. Look for
@page,@media print,size:,margin,transform, fixedheight, and overflow rules. - Choose an owner. Use either API-owned or CSS-owned sizing, not both.
- Baseline with A4 or Letter. A standard format distinguishes precedence errors from custom-size rounding.
- Set margins explicitly. Use zero margins for a full-bleed test or the exact physical values required by the document.
- Wait for layout inputs. Complete navigation, fonts, images, data fetches, and client-side rendering before calling
page.pdf(). - Inspect print styles. Measure the DOM after print emulation and check which elements overflow the page box.
- Inspect the PDF itself. Verify physical page dimensions with a PDF inspector, not only a viewer’s zoom or fit-to-window display.
- Reproduce on deployment versions. Compare the exact Puppeteer and Chromium versions used locally and in production; print behavior can change with browser updates.
Common symptoms and targeted fixes
| Symptom | Likely cause | First fix |
|---|---|---|
format: 'A4' appears ignored |
A wrapper passes another option, or CSS is given priority | Log options; remove conflicting dimensions; set preferCSSPageSize: false unless CSS should own the size |
| Custom width and height do not apply | format is present |
Remove format and keep physical-unit dimensions |
| Unexpected white border | Protocol, Puppeteer, CSS, or body margins | Set all intended margins explicitly and inspect @page and print body styles |
| Screen layout differs in PDF | Print media rules | Inspect with print emulation, or call emulateMediaType('screen') when screen rules are intentional |
| Blank or extra final page | Overflow, borders, transforms, fractional dimensions, or content fragmentation | Strip those styles in a minimal reproduction, then add them back incrementally |
| Text shifts between runs | Fonts, images, or async content are late | Wait for navigation, document.fonts.ready, images, and application data |
| Colors look washed out | Print color adjustment | Use -webkit-print-color-adjust: exact where exact colors are required |
Reliability and performance considerations
Use a single browser instance with controlled pages for batch work, but isolate jobs whose scripts or cookies could interfere. Reuse a deterministic viewport and user agent. Avoid relying on an arbitrary sleep as the only readiness condition; wait for a selector, network state, fonts, and images that define your actual layout.
Keep the PDF options in one logged configuration object. This makes differences between local and production runs visible and prevents a helper from silently adding a conflicting format. For custom paper, record the physical units and the browser version alongside the generated file so a later discrepancy can be reproduced.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Or skip the browser setup
ScreenshotNeo provides a website screenshot and PDF API when you do not want to maintain Puppeteer and Chromium. Its PDF endpoint accepts paper size, margins, landscape mode, and page ranges, while its capture options cover full-page output, CSS selectors, custom CSS and JavaScript, waiting conditions, headers, cookies, user agents, timezone, geolocation, and more. Before capture it accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be disabled.
Only clean shots are billed. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and each response identifies the result with X-Page-Verdict and X-Billed headers. An MCP server lets Claude, Cursor, and other MCP clients use take_screenshot, get_page_info, and capture_pdf.
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 and the full API. Equivalent calls:
Free tools Windows power users keep installed
One-click scans. No signup required.
import requests
r = requests.get(
"https://api.screenshotneo.com/v1/shot",
params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"},
timeout=90
)
r.raise_for_status()
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);
require('fs').writeFileSync('shot.webp', Buffer.from(await res.arrayBuffer()));
The Free plan includes 1,000 shots per month with no card. Paid plans start at $5 for 3,000 shots; every feature is on every plan. Create a free ScreenshotNeo account.
Best Value
- 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.
When to use each ownership model
| Requirement | Recommended owner | Configuration |
|---|---|---|
| Stable standard paper such as A4 or Letter | Puppeteer API | format, explicit margins, preferCSSPageSize: false |
| Custom label or print layout already defined in CSS | CSS | One @page rule, preferCSSPageSize: true |
| Screen appearance rather than print appearance | Media emulation plus either size owner | emulateMediaType('screen'), then explicit PDF size |
| Production capture without browser maintenance | Hosted API | Use ScreenshotNeo’s documented endpoint and options |
Frequently Asked Questions
Does changing page.setViewport() change the PDF paper size?
No. It changes the browser’s layout viewport. Set paper dimensions with page.pdf() or a CSS @page rule.
Can I use preferCSSPageSize without writing an @page rule?
You can, but there is no CSS size to take precedence. Define an explicit @page size when CSS ownership is intended.
Why does a PDF viewer report a different size than my CSS pixels?
CSS pixels describe layout; PDF dimensions are physical units. Verify the page box in a PDF inspector and keep dimensions in mm, cm, or in.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problemsShould I fix an extra page with a smaller viewport?
Usually not. An extra page is caused by print-area overflow or fragmentation. Inspect margins, borders, transforms, fixed heights, and fractional dimensions first.
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.

