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

Use Puppeteer’s page.pdf() method: launch Puppeteer’s bundled browser, navigate to the page, wait for the content your PDF needs, then save the generated PDF. Puppeteer uses print CSS by default; call page.emulateMediaType('screen') first if you want the screen layout instead. The examples below make the key output choices explicit rather than relying on defaults.

Generate a PDF with Puppeteer

Install Puppeteer in your Node.js project, then save this as an ES module file such as capture.mjs. Replace the example URL as needed.

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,
    preferCSSPageSize: true,
  });
} finally {
  await browser.close();
}

This follows Puppeteer’s PDF generation guide: launch a browser, create a page, navigate, and call page.pdf(). The example uses networkidle2, but no single navigation wait guarantees that every page’s content is ready. For a site that renders important content after navigation, wait for the relevant selector or application-specific readiness condition before creating the PDF.

  1. puppeteer.launch() starts the browser; browser.newPage() creates a page to print.
  2. page.goto() navigates to the target. Puppeteer’s general wait option defaults to the load lifecycle event; this example explicitly asks for networkidle2. See the WaitForOptions reference.
  3. page.pdf() writes the PDF to page.pdf because a path is supplied.
  4. The finally block closes the browser even if navigation or PDF generation throws an error.

Wait for the right content before printing

Navigation completing and page content being ready are not always the same thing. A page may render data after an API call, load images lazily as the page is scrolled, or keep network activity open through polling. Choose a readiness condition that matches the content you need; use an explicit selector or application condition when the PDF depends on a particular element.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
Epson Workforce ES-50 Compact & Lightweight Mobile Document Scanner
  • PORTABLE SCANNER FOR USE ON-THE-GO — The fastest and lightest mobile single-sheet-fed compact document scanner in its class¹
  • QUICK DOCUMENT SCANNING ― This Epson ultra-fast scanner scans a single page as quickly as 5.5 seconds²; Windows and Mac compatible
  • VERSATILE PAPER HANDLING ― Portable scanner scans documents up to 8.5 x 72 in; Also easily digitizes receipts and ID cards to make accounting, bookkeeping, and organizing simpler
  • INTUITIVE, HIGH-SPEED SOFTWARE — Epson ScanSmart Software³ is a smart tool allowing you to easily scan, review, and save; Stay organized easily with the help of this Epson scanner
  • EASY SETUP — USB-powered connect to your computer for quick and simple scanning; No batteries or external power supply required to operate portable document scanner; Standard Connectivity: USB 2.0

Wait for a selector

For a known element that appears when the printable content is ready, wait for it after navigation:

await page.goto('https://example.com', { waitUntil: 'domcontentloaded' });
await page.waitForSelector('#report-content');
await page.pdf({ path: 'report.pdf', format: 'A4', printBackground: true });

Replace #report-content with a selector that exists on the target page. A selector only establishes readiness for the element you chose; it does not prove that unrelated content, images, or fonts have finished loading.

Wait for network activity to settle

Puppeteer also provides page.waitForNetworkIdle(). Its documented behavior includes waiting at least the configured idle time; it can be useful for pages whose content is driven by requests, but ongoing polling or other background traffic can make network-idle waits unsuitable. See the Page API reference.

Use networkidle2 or a network-idle wait as a page-specific choice, not as a universal signal that a site is fully rendered. For pages that never become idle, wait for the content you actually need instead.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Sale
Brother DS-640 Compact Mobile Document Scanner, (Model: DS640)
  • FAST SPEEDS - Scans color and black and white documents a blazing speed up to 16ppm (1). Color scanning won’t slow you down as the color scan speed is the same as the black and white scan speed.
  • ULTRA COMPACT – At less than 1 foot in length and only about 1. 5lbs in weight you can fit this device virtually anywhere (a bag, a purse, even a pocket).
  • READY WHENEVER YOU ARE – The DS-640 mobile scanner is powered via an included micro USB 3. 0 cable allowing you to use it even where there is no outlet available. Plug it into you PC or laptop and you are ready to scan.
  • WORKS YOUR WAY – Use the Brother free iPrint&Scan desktop app for scanning to multiple “Scan-to” destinations like PC, Network, cloud services, Email and OCR. (2) Supports Windows, Mac and Linux and TWAIN/WIA for PC/ICA for Mac/SANE drivers. (3)
  • OPTIMIZE IMAGES AND TEXT – Automatic color detection/adjustment, image rotation (PC only), bleed through prevention/background removal, text enhancement, color drop to enhance scans. Software suite includes document management and OCR software. (4)

Choose print CSS or screen CSS

page.pdf() renders using the print CSS media type. That means print-specific rules, such as @media print and @page, can affect layout. To render with the screen stylesheet, emulate screen media before calling page.pdf():

await page.emulateMediaType('screen');
await page.pdf({ path: 'screen-layout.pdf', format: 'A4', printBackground: true });

Puppeteer’s Page class reference documents PDF generation with print media and the media-emulation method. The choice depends on the result you want: print CSS is generally appropriate for a document intended for paper or conventional PDF reading, while screen CSS can preserve the web layout more closely.

Set paper size, margins, and page ranges

The documented PDF options include format, width, height, landscape, margin, and pageRanges. If you provide format, it takes priority over width and height. Specify the geometry and margins explicitly when the output must meet a particular print or document requirement.

Option What it controls
format Named paper size, such as 'A4'. When specified, it takes priority over width and height.
width, height Paper dimensions when not overridden by format.
landscape Whether to use landscape orientation.
margin Page margins.
pageRanges Which pages to include in the generated PDF.
preferCSSPageSize Whether CSS @page size takes priority over the PDF options’ paper size. Its documented default is false; when false, content is scaled to fit the selected paper size.

The full option definitions are in Puppeteer’s PDFOptions reference. With preferCSSPageSize: true, as in the first example, CSS @page sizing can govern the paper size. If you need to control size from your script instead, set format or dimensions and leave CSS page sizing preference off.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Canon imageFORMULA R10 - Portable Document Scanner, USB Powered, Duplex Scanning, Document Feeder, Easy Setup, Convenient, Perfect for Mobile Users, White
  • STAY ORGANIZED – Easily convert your paper documents into digital formats like searchable PDF files, JPEGs, and more.Power Consumption : 2.5W or less (Energy Saving Mode: 0.7W). Suggested Daily Volume : 500 scans..Does it contain liquid: no
  • CONVENIENT AND PORTABLE –lightweight and small in size, you can take the scanner anywhere from home offices, classrooms, remote offices, and anywhere in between
  • HANDLES VARIOUS MEDIA TYPES – Digitize receipts, business cards, plastic or embossed cards, reports, legal documents, and more
  • FAST AND EFFICIENT – No technical hurdles or complicated setups here; easily scan both sides of a document at the same time, in color or black-and-white, at up to 12 pages-per-minute, and with a 20 sheet automatic feeder
  • BROAD COMPATIBILITY – Works with both Windows and Mac devices, be it laptop or computer

Include backgrounds and control printed colors

Background graphics are omitted by default because printBackground defaults to false. Set printBackground: true when the PDF needs background colors or images. Puppeteer also notes that printed colors are modified by default; its Page reference points to -webkit-print-color-adjust when exact color rendering is needed. Add the rule to the page’s CSS where you control it:

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

This affects print rendering; it does not replace checking the PDF’s actual layout and colors on the target page.

Control headers, footers, and fonts

Set displayHeaderFooter to enable headers and footers, then provide headerTemplate and/or footerTemplate. The documented placeholders include date, title, URL, page number, and total pages. Puppeteer’s PDF options also document waitForFonts, which defaults to true and waits for document.fonts.ready. The reference notes this may require bringing a background page to the front. Check the PDFOptions reference for supported template details and options for the installed version.

Save to a file, return bytes, or stream the PDF

Write directly to a path

Use the path option when the application should save the file to disk:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
IRIScan Express 4 Black Compact Portable USB Simplex Document Scanner, 8 PPM for Contracts, Invoices and Business Cards, Compatible with Windows, Readiris PDF Included
  • IRIScan Express, portable scanner : scans color and black and white documents a blazing speed up to 8ppm simplex. Color scanning won’t slow you down as the color scan speed is the same as the black and white scan speed.
  • IRIScan Express mobile scanner is powered via an included micro USB 2. 0 cable allowing you to use it even where there is no outlet available. Plug it into you PC or laptop and you are ready to scan. USB cable provided. AC Adapter not provided and not needed.
  • IRIScan flatbed scanner uses a simplex scanning mode allows for quick and straightforward scanning of single-sided documents. IRIScan with its full portable features is the ideal document scanners for computers.
  • IRIScan document scanner : Versatile scanning capabilities, including scanning to Word, PDF, and Excel formats with companion software provided Readiris OCR
  • Receipt scanner and card scanner with Additional features include scanning business cards directly to Outlook, photo scanning, and receipt scanning for efficient document management
await page.pdf({ path: 'page.pdf', format: 'A4' });

Work with returned PDF bytes

If path is omitted, page.pdf() returns a Uint8Array. You can pass those bytes to the storage or response layer your application uses:

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

Use a readable stream

For an application that needs a readable stream, use page.createPDFStream(). Puppeteer documents both PDF generation methods in the Page class reference; choose the output form that fits how your program stores or serves the document.

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

Browser runtime and version considerations

Puppeteer says it is only guaranteed to work with its bundled browser. The LaunchOptions reference documents headless mode as enabled by default. If you configure a separately installed browser or another release channel, verify compatibility with the Puppeteer version and browser you deploy.

The linked PDFOptions and Page API references identify version 25.12.0, while the PDF guide is on Puppeteer’s next documentation path. APIs and defaults may change, so check the references matching your installed package before relying on a version-sensitive option.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Canon Canoscan Lide 300 Scanner (PDF, AUTOSCAN, Copy, Send)
  • Scanner type: Document
  • Connectivity technology: USB
  • With Auto Scan Mode, the scanner automatically detects what you're scanning
  • Digitize documents and images

Common problems and fixes

  • Background colors or images are missing: Set printBackground: true; backgrounds are omitted by default.
  • The PDF has print styling instead of the visible screen layout: Call page.emulateMediaType('screen') before page.pdf().
  • Content is missing or half-rendered: Do not assume navigation completion means application data is ready. Wait for the relevant selector or application-specific condition before printing.
  • Network-idle waiting never finishes: A page may continue polling or loading background requests. Replace the idle wait with a condition tied to the content needed in the PDF.
  • The output uses an unexpected paper size: Check whether format overrides width and height, and whether preferCSSPageSize lets CSS @page sizing take priority.
  • Colors differ from the page: Printed colors are modified by default. If you control the page’s CSS and need exact print colors, use -webkit-print-color-adjust: exact.
  • A separately installed browser behaves unexpectedly: Puppeteer only guarantees operation with its bundled browser. Verify the configured runtime and version compatibility.
  • The PDF file is not created where expected: Check the supplied path and ensure the process can write to that location. If you omit path, handle the returned bytes instead of expecting a file.

Or skip the browser setup

If you need a screenshot or PDF through an API rather than managing a browser runtime, ScreenshotNeo is a website screenshot API and MCP server for developers. Its one-request PDF option accepts PDF settings such as paper size, margins, landscape, and page ranges. This is a different workflow from Puppeteer: the example below requests a screenshot image.

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 API usage. ScreenshotNeo accepts cookie and consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and responses include X-Page-Verdict and X-Billed headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for 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.

Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month with no card.

Frequently Asked Questions

Does Puppeteer save the PDF as a file or return data?

With a path option, page.pdf() writes a file; without one, it returns a Uint8Array. Puppeteer also documents page.createPDFStream() for stream-based output.

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

Which browser should I use with Puppeteer in production?

Puppeteer guarantees compatibility with its bundled browser. If you configure another browser, verify compatibility with the installed Puppeteer and browser versions.

Quick Recap

SaleBestseller No. 3
Canon imageFORMULA R10 - Portable Document Scanner, USB Powered, Duplex Scanning, Document Feeder, Easy Setup, Convenient, Perfect for Mobile Users, White
Canon imageFORMULA R10 - Portable Document Scanner, USB Powered, Duplex Scanning, Document Feeder, Easy Setup, Convenient, Perfect for Mobile Users, White
BROAD COMPATIBILITY – Works with both Windows and Mac devices, be it laptop or computer; This product is not intended for scanning photographs on photo paper / photographic media
$153.00
Bestseller No. 4
IRIScan Express 4 Black Compact Portable USB Simplex Document Scanner, 8 PPM for Contracts, Invoices and Business Cards, Compatible with Windows, Readiris PDF Included
IRIScan Express 4 Black Compact Portable USB Simplex Document Scanner, 8 PPM for Contracts, Invoices and Business Cards, Compatible with Windows, Readiris PDF Included
Find our Software here : irislink.com/start; IRIScan Express is only compatible Windows platform and not macintosh
$129.00
Bestseller No. 5
Canon Canoscan Lide 300 Scanner (PDF, AUTOSCAN, Copy, Send)
Canon Canoscan Lide 300 Scanner (PDF, AUTOSCAN, Copy, Send)
Scanner type: Document; Connectivity technology: USB; With Auto Scan Mode, the scanner automatically detects what you're scanning
$75.00

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.