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

To save a web page as a PDF with Puppeteer, call page.pdf(). It renders the page using print CSS by default and can either write a file or return PDF bytes for your application to handle. This is different from clicking Chrome’s visible Print Preview dialog and trying to retrieve the dialog’s result: Puppeteer’s documented PDF workflow generates the PDF directly from the page.

What “download a PDF from print preview” can mean

First identify which document you have and what you want to automate:

  • HTML page to a printable PDF: use Puppeteer’s page.pdf(). This is the documented approach for generating a PDF from rendered page content. It uses print CSS by default. Puppeteer Page.pdf() API
  • PDF produced by Chrome’s interactive print dialog: the Puppeteer references cited here do not document extracting or downloading the result of that visible dialog. For an automated page-to-PDF result, call page.pdf() instead; do not treat it as an automation of the dialog.
  • An existing PDF opened in a browser: that is not the same as printing an HTML page to PDF. The page.pdf() references describe page rendering, not a method for downloading the source PDF displayed in Chrome’s viewer.

The steps below cover the first case: generating a PDF from a web page with Puppeteer.

Generate a PDF and save it to disk

Install Puppeteer in a Node.js project, then use page.pdf({ path }) to write the PDF. The following is a complete example for a public page; change the URL and output filename as needed.

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.
import puppeteer from 'puppeteer';

const browser = await puppeteer.launch();

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

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

Run it from a project configured for ES modules after installing Puppeteer (for example, with npm install puppeteer). The official guide uses the same basic navigation-and-PDF pattern and explains that PDF generation waits for fonts by default. Puppeteer PDF generation guide

A relative path is resolved from the Node process’s working directory, not necessarily from the directory containing the script. Use an absolute path if your application needs a predictable destination. Puppeteer PDFOptions

Return PDF bytes instead of writing a file

Omit path when you want to handle the document in code. page.pdf() returns a Uint8Array; your application can pass those bytes to its own storage or HTTP-response logic. The API documents the bytes, but the response headers and browser-download behavior are up to your application.

const pdfBytes = await page.pdf({
  format: 'A4',
  printBackground: true,
});

// Pass pdfBytes to your own storage or HTTP response code.

The Puppeteer Page API also lists createPDFStream(). Consider it when your application’s data flow benefits from a stream, and check the API documentation for the Puppeteer version installed in your project. Puppeteer Page API

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.
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.

Choose print or screen styling

By default, Puppeteer generates the PDF with the page’s print CSS media type. That is usually appropriate for a document intended to be printed: print styles can hide navigation, change typography, or rearrange content. If you specifically want the page’s screen styling, set the media type before calling page.pdf().

await page.emulateMediaType('screen');
const pdfBytes = await page.pdf({ format: 'A4' });

For print-specific styles, use CSS such as @media print and @page in the page itself. Check the result rather than assuming the browser view and PDF will match. Puppeteer’s API notes that printing may modify colors; the CSS property -webkit-print-color-adjust can request exact colors, but verify its effect with the page’s own styles. Page.pdf() API

Set paper, margins, pages, and backgrounds

PDF options let you control the document’s layout. These settings are useful when a default printout is clipped, too small, missing visual backgrounds, or needs a particular paper size. Consult the installed version’s PDFOptions reference for the full option definitions.

Need Option or approach What to check
Choose a standard sheet size format, such as 'A4' Confirm the selected paper size matches the intended output.
Set a custom page size width and height Check the units and confirm the page content fits those dimensions.
Control whitespace around content margin Inspect edges for clipped text or unexpectedly large margins.
Use a page’s CSS page dimensions preferCSSPageSize: true This gives CSS @page sizing priority over explicit format or dimensions.
Print background colors and images printBackground: true Background graphics are off by default.
Limit the output to selected pages pageRanges Check the resulting page count and numbering against the requested range.
Change page orientation or scale landscape or scale Review tables and wide content for readability and clipping.

For example, to preserve a page’s CSS-defined paper size and include backgrounds, use:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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.
const pdfBytes = await page.pdf({
  preferCSSPageSize: true,
  printBackground: true,
});

Do not set conflicting sizing rules without checking which one you intend to win. If the document uses CSS @page dimensions, preferCSSPageSize determines whether those dimensions take priority over the explicit PDF format or dimensions.

Wait for the page to be ready

A successful navigation does not guarantee that every page has finished loading its application data, images, or other asynchronous content. Puppeteer’s PDF guide shows waitUntil: 'networkidle2' as an example, but that condition is not a universal signal that a site’s own rendering work is complete. If the page has a known ready state, wait for it before generating the PDF.

await page.goto('https://example.com', { waitUntil: 'networkidle2' });
await page.waitForSelector('#report-ready');
const pdfBytes = await page.pdf({ format: 'A4' });

Replace #report-ready with a selector that actually appears only when the relevant content is ready. Avoid waiting on an arbitrary delay unless the page gives you no reliable readiness condition; a fixed delay can waste time on fast runs and still be too short on slow ones.

Puppeteer waits for fonts by default before producing the PDF. The PDF options reference documents waitForFonts as enabled by default and a default PDF timeout of 30,000 milliseconds. It also notes that a page in the background may need to be brought to the front for document.fonts.ready to resolve. If font loading is the problem, check the font requests and page visibility before increasing timeouts. PDFOptions reference

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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

Handle a PDF in an application

When generating a file on the server, save it where the application expects it and make sure the process has permission to write there. When returning bytes from an HTTP endpoint, the application must implement the response and download behavior; page.pdf() supplies the document bytes, not a ready-made browser download flow. For larger or streaming-oriented application flows, compare the Page API’s createPDFStream() method with the byte-returning method and use the one supported by your installed Puppeteer version.

Keep the browser lifecycle bounded: close the page or browser when the job finishes, including on errors. If a PDF is incomplete, first ensure the page reached the state that contains all needed content, then inspect page sizing, margins, print CSS, and the generated document. A browser process that remains open after a failed job can also consume resources in a long-running service.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common problems and fixes

  • The script opens print preview but no file appears: the interactive dialog and page.pdf() are separate approaches. For a generated file, call page.pdf({ path: 'page.pdf' }); the documented API does not describe retrieving the visible dialog’s output.
  • The file is blank or missing late-loading content: navigation completion may have occurred before the page’s application finished rendering. Wait for a page-specific selector or readiness condition before calling page.pdf().
  • Fonts are missing or the call reaches its timeout: verify font requests and readiness. The API waits for fonts by default, with a documented default timeout of 30,000 milliseconds; a background page can prevent document.fonts.ready from resolving, so bring it to the front if needed.
  • Background colors or images are absent: set printBackground: true. It is off by default.
  • The output has unexpected colors: printing can alter colors. Inspect the page’s print CSS and test -webkit-print-color-adjust rather than assuming the PDF will preserve screen colors.
  • Content is clipped or paginated badly: review format, width, height, margin, scale, orientation, and any CSS @page rules. If CSS page size should control the output, set preferCSSPageSize: true.
  • The PDF is saved somewhere unexpected: a relative path is relative to the process working directory. Log or resolve that directory, or provide an absolute path.
  • You need to download a PDF already displayed in Chrome: generating a new PDF of the page is not the same as downloading that existing PDF. The Page.pdf() references do not establish a viewer-download method; use the source document or an application-specific download route.

Use Chrome Headless from the command line instead

If you do not need to control a page through Puppeteer, Chrome Headless documents the --print-to-pdf command-line option as an alternative for PDF generation. This is a separate workflow from Puppeteer’s Page API. Chrome Headless command-line reference

Or skip the browser setup

If your actual need is a clean website capture rather than a Puppeteer-controlled print workflow, ScreenshotNeo is a website screenshot API and MCP server. A single request can return a PNG, JPEG, WebP, or PDF. For example, this supplied API call captures a page as WebP:

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 the API options and PDF output setup. ScreenshotNeo removes cookie and consent banners, newsletter popups, and chat widgets before capture; those steps can be turned off. Bot checks, blank pages, failed loads, timeouts, 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 for AI agents and MCP clients. The free plan includes 1,000 shots a month with no card; paid plans start at $5 for 3,000 shots.

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

Frequently Asked Questions

Does Puppeteer use the same Chrome version on every machine?

No. Browser behavior can vary with the Puppeteer package and browser installed in the environment. Check the Puppeteer version and its matching API documentation when a PDF option or rendering result differs.

Can I use page.pdf() to create a PDF from HTML already in a page?

Yes. It generates a PDF from the rendered page content, so the page can be navigated to or populated by your application before you call the method.

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.