Generate a PDF with Puppeteer by loading the page, waiting for the content your application needs, and calling page.pdf() with deliberate print settings. Puppeteer renders using print CSS by default, so page size, margins, backgrounds, colors, and readiness checks can change the result substantially. The reliable approach is to define the PDF’s intended output, then test it with the same Puppeteer and browser versions you will deploy.
Generate a PDF with Puppeteer
Install Puppeteer in your Node.js project, launch its bundled browser, navigate to a page, and call page.pdf(). This complete example writes a Letter-size PDF with margins and background graphics enabled:
import puppeteer from 'puppeteer';
const url = process.argv[2] ?? 'https://example.com';
const browser = await puppeteer.launch();
try {
const page = await browser.newPage();
await page.goto(url, { waitUntil: 'networkidle2' });
await page.pdf({
path: 'page.pdf',
format: 'Letter',
printBackground: true,
margin: {
top: '0.5in',
right: '0.5in',
bottom: '0.5in',
left: '0.5in'
}
});
} finally {
await browser.close();
}
Run it in a project with Puppeteer installed, for example by saving it as make-pdf.mjs and executing node make-pdf.mjs https://example.com. The navigation option in this example follows Puppeteer’s guide, but network quiet is not proof that your app has finished rendering its own content. For a dashboard, report, or other client-rendered page, wait for a specific element or application signal before calling page.pdf().
Make page readiness explicit
PDF generation can faithfully print a page that is still incomplete. A navigation event only describes browser loading; application data, charts, and lazy-loaded images may have a separate lifecycle. Choose the wait condition that reflects the page you are capturing rather than relying on a generic delay.
#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.
Wait for an application-specific condition
When the page exposes a stable element after rendering, wait for it before printing:
await page.goto(url, { waitUntil: 'domcontentloaded' });
await page.waitForSelector('[data-report-ready="true"]');
await page.pdf({ path: 'report.pdf', format: 'A4' });
Replace the selector with an element that your application only exposes when the necessary data is ready. If the page has a known rendering promise or other readiness signal, wait on that instead. Avoid treating networkidle2 as a universal guarantee: some pages keep connections open, while others finish network activity before their visual content is ready.
Wait for fonts
Page.pdf() waits for fonts by default. If PDF generation hangs at font readiness while the page is running in the background, Puppeteer documents bringing the page to the front as a remedy:
await page.bringToFront();
await page.pdf({ path: 'report.pdf' });
Use this only where the background-page font wait is relevant; it does not replace application-specific readiness checks.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallRank #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.
Choose print or screen rendering
Puppeteer’s PDF method uses the print media type by default. That means print-specific CSS such as @media print rules can hide navigation, change layout, or alter colors compared with the page in a normal browser window.
- Use print media when the PDF is intended to be a document, report, or printable page. Add and test print CSS for the desired page breaks, visibility, and layout.
- Use screen media when the output should resemble the screen-rendered page. Call
await page.emulateMediaType('screen')beforepage.pdf().
Changing media type changes which CSS rules apply; it does not guarantee an exact visual match across every page or browser. Verify the generated PDF itself.
Set paper size, dimensions, and margins
Do not leave the PDF’s paper contract to defaults if recipients or a downstream print workflow expect a particular format. Puppeteer documents Letter as the default format and no margins by default. Set the format or dimensions and margins explicitly when those defaults are not what you want.
format takes priority over width and height. If your document’s CSS @page rule should determine paper size, set preferCSSPageSize: true; otherwise, that option defaults to false and the API paper-size settings take priority. Choose one authority deliberately to avoid confusing conflicts between CSS and the call’s options.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →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.
await page.pdf({
path: 'report.pdf',
format: 'A4',
landscape: true,
margin: {
top: '12mm',
right: '10mm',
bottom: '12mm',
left: '10mm'
}
});
Use the orientation and dimensions appropriate for the document: a wide table may need landscape output, while a standard text report may fit portrait pages. Inspect page breaks, clipping, and whitespace at the selected size rather than assuming that a setting suitable for one page is suitable for another.
Control backgrounds and printed colors
Background graphics are off by default. Set printBackground: true if the PDF needs background fills, colored panels, or other background graphics. Separately, Chromium adjusts PDF colors for printing by default. When exact CSS colors matter, use -webkit-print-color-adjust: exact in the relevant stylesheet and verify the output.
@media print {
.report-highlight {
-webkit-print-color-adjust: exact;
print-color-adjust: exact;
}
}
Color adjustment and background rendering are separate concerns: enabling backgrounds does not by itself promise exact colors. Use these options only when they serve the document’s output requirements, and check the result in a PDF viewer and any actual print workflow that matters.
Tune the remaining PDF options
Once the page renders correctly, adjust output options against a representative document. Puppeteer’s PDF options include orientation, scale, page ranges, header and footer templates, and a timeout. In the documentation version 25.12.0, scale is documented from 0.1 to 2 and the default timeout is 30,000 milliseconds. These are versioned option facts, so confirm the reference for the Puppeteer version installed in your project before relying on them.
Recommended Free Tools
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
- Scale: Use a value within the documented range for your version. Scaling can help fit content, but inspect text size and clipping.
- Page ranges: Request only needed pages for partial exports, and check that the selected ranges match the document’s actual pagination.
- Headers and footers: Add them only when the document needs repeated page information; test their layout with the chosen margins.
- Timeout: Set a value suitable for the page and environment, especially when pages load data or fonts slowly. A longer timeout does not solve a page that never reaches readiness.
- Outline and tagged output: The current reference labels these options experimental. Validate them against your exact deployed version and intended PDF consumers before depending on them.
Use a compatible browser build
Puppeteer guarantees compatibility with its bundled browser. If you configure Puppeteer to use a separately installed Chrome, compatibility is at your own risk, so validate that browser build with your app and PDF options before deploying it. Pinning and testing the combination used in production makes changes to rendering easier to diagnose.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Troubleshoot common PDF problems
The PDF is blank or missing data
The page may have navigated successfully while application content was still loading. Replace a generic wait with a selector or other app-specific readiness condition, then verify that the content exists before printing.
The PDF layout differs from the browser
page.pdf() uses print media by default. Check print styles and @page rules. If the intended PDF should use screen CSS, call page.emulateMediaType('screen') before generating it.
Colors or backgrounds are missing
Background graphics are disabled by default, so enable printBackground when required. For exact CSS colors, apply -webkit-print-color-adjust: exact to the relevant print styles and inspect the resulting PDF.
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.
Text wraps or pages break in unexpected places
Check the selected paper size, orientation, margins, and whether preferCSSPageSize should allow CSS @page sizing to take priority. Then review the print stylesheet for page-break behavior and test with representative long content.
Font waiting does not finish
Puppeteer waits for fonts by default. If the page is in the background, bring it to the foreground with page.bringToFront() and retry. If the delay persists, inspect whether the page’s fonts can load and whether your chosen readiness condition is being reached.
A different Chrome version changes output
Puppeteer’s compatibility guarantee applies to its bundled browser, not an independently installed Chrome. Test the external build you plan to deploy, or use Puppeteer’s bundled browser for the documented compatibility path.
Or skip the browser setup
If you need a PDF from a URL without running Puppeteer yourself, ScreenshotNeo provides a website screenshot API that can return a PDF. For an API call, use the PDF output option supported by the service:
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
curl -G "https://api.screenshotneo.com/v1/shot"
-d access_key=YOUR_API_KEY
--data-urlencode url=https://example.com
-d format=pdf
-o page.pdf
See the ScreenshotNeo documentation for request options. Cookie banners, popups, and chat widgets are removed before the shot; bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots, and the Free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. Sign up for free.
Operational considerations
PDF work is only as reliable as the page state, rendering environment, and output settings you control. Generate PDFs from representative pages during development, including unusually long reports, pages with charts or images, and layouts sensitive to page breaks. Validate the output in the browser build you will deploy, and make your readiness condition reflect the content rather than an arbitrary wait. Puppeteer’s official documentation establishes the option behavior described here, but it does not establish a universal best setting or comparative performance result: choose based on the PDF contract your application needs.
Frequently Asked Questions
Does Puppeteer generate PDFs using print CSS?
Yes. `page.pdf()` uses the print media type by default; call `page.emulateMediaType(‘screen’)` first if the PDF should use screen media.
What browser does Puppeteer guarantee compatibility with?
Puppeteer guarantees compatibility with its bundled browser. A separately installed Chrome build should be validated with your deployed version and workload.
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.

