DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk6 min

How to Capture a Webpage as a PDF with Puppeteer

Use Puppeteer’s page.pdf() to save a webpage as a PDF, with control over print styling, paper size, margins, backgrounds, and output handling.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Puppeteer’s page.pdf() method: launch its bundled browser, navigate to the page, wait for the content you need, then save the resulting PDF. Puppeteer prints with print CSS by default; set page size, margins, and background handling explicitly when the output needs to be predictable.

Capture a webpage as a PDF

Install Puppeteer in a Node.js project, then run this ES module script. It navigates to a URL, writes an A4 PDF with background graphics, and closes the browser even if capture fails.

As an Amazon Associate I earn from qualifying purchases.

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

Save it as capture.mjs and run node capture.mjs https://example.com. Puppeteer’s documented workflow is to launch the browser, create a page, navigate, and call page.pdf(). The guide’s example uses networkidle2, but that wait condition is not a guarantee that every site’s application content is ready. See the Puppeteer PDF generation guide and check the API references matching your installed package version.

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

Wait for the content you need

The script’s networkidle2 navigation condition is a reasonable starting point, not a universal readiness test. Pages that poll continuously, load content after navigation, or render from application state may need a page-specific condition before printing.

#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 page element

If the page has a reliable element that appears when the content is ready, wait for that selector after navigation:

await page.goto(url, { waitUntil: 'domcontentloaded' });
await page.waitForSelector('#article-content');
await page.pdf({ path: 'page.pdf', format: 'A4', printBackground: true });

Replace #article-content with a selector that exists on the target page. Puppeteer’s wait options document navigation lifecycle events such as load (the general default); select the event and subsequent readiness check for the page rather than assuming one load event fits every site. The Page API also documents waitForNetworkIdle(), which waits for at least its configured idle time. See WaitForOptions and the Page API.

Fonts and background pages

Puppeteer’s PDF generation guide says that, by default, page.pdf() waits for fonts to load. The PDF options reference documents waitForFonts as enabled by default; it also notes that this may require bringing a background page to the front. If font-dependent layout is wrong, check that the fonts actually load and that the page is not being kept in the background before changing this setting.

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

Choose print or screen styling

page.pdf() renders using the print CSS media type by default, so print stylesheets and print-specific rules determine the layout. If the PDF should resemble the on-screen page instead, emulate screen media before calling page.pdf():

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)
await page.emulateMediaType('screen');
await page.pdf({ path: 'page.pdf', format: 'A4', printBackground: true });

This changes the media type used for rendering; it does not bypass the rest of the page’s layout or readiness requirements. Puppeteer also notes that printed colors are modified by default. If exact color rendering matters, its Page reference points to the CSS property -webkit-print-color-adjust. See the Page class reference.

Set paper size, margins, and page range

The PDF options let you define paper geometry and which pages to include. Set these values deliberately rather than depending on defaults.

  • format selects a standard paper format such as A4. When format is set, it takes priority over width and height.
  • Use width and height when you need custom dimensions instead of a named format.
  • Set landscape: true for landscape orientation.
  • Use margin to define page margins, and pageRanges to restrict output to selected pages.
  • Set preferCSSPageSize: true when the page’s CSS @page size should take priority over the PDF options’ dimensions. Its documented default is false; with that default, content is scaled to fit the requested paper size.

For example, this uses landscape A4, explicit margins, and a page range:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
await page.pdf({
  path: 'selected-pages.pdf',
  format: 'A4',
  landscape: true,
  margin: { top: '12mm', right: '12mm', bottom: '12mm', left: '12mm' },
  pageRanges: '1-3',
  printBackground: true,
});

If the document’s own @page rules should control the paper size, use preferCSSPageSize: true and avoid setting competing geometry without a reason. The available fields and documented defaults are in Puppeteer’s PDFOptions reference.

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 headers or footers

Background graphics are omitted by default: printBackground defaults to false. Set it to true when the PDF should include background colors or images.

Headers and footers are controlled by displayHeaderFooter, headerTemplate, and footerTemplate. The documented template placeholders include date, title, URL, page number, and total pages. Configure the templates when you need those details; do not assume headers or footers will appear unless enabled. Full option details are in the PDFOptions API reference.

Save to a file, use the PDF bytes, or stream the result

Write directly to a path

Set path in page.pdf(), as in the runnable example, to write a PDF file.

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.

Keep the returned bytes

When path is omitted, page.pdf() returns a Uint8Array. This is useful when the surrounding application needs to store or serve the generated PDF itself:

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
const pdfBytes = await page.pdf({ format: 'A4', printBackground: true });

Use a readable stream

Use page.createPDFStream() when your application needs a readable stream rather than a path or returned byte array. Both PDF-generation methods are documented in the Page API.

Browser runtime and version considerations

Puppeteer says it is only guaranteed to work with its bundled browser. The example uses the browser installed for the package by the normal Puppeteer setup; if you configure a separately installed browser or another release channel, check compatibility and deployment implications for the versions you are using. Puppeteer’s LaunchOptions reference documents headless mode as enabled by default.

The PDFOptions and Page references identified for this guide are version 25.12.0, while the PDF generation guide is on Puppeteer’s next documentation path. APIs and defaults can change, so check the documentation that matches your installed Puppeteer version before relying on version-sensitive syntax or behavior.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common PDF problems

The PDF is missing background colors or images

Set printBackground: true. Its documented default is false.

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

The PDF layout differs from the browser view

Puppeteer uses print media for PDF generation by default. Use page.emulateMediaType('screen') before generating the PDF if screen CSS is the intended layout. If print media is correct but colors differ, check the print color behavior and the documented -webkit-print-color-adjust guidance.

The output has the wrong paper size or scaling

Check the interaction between format, width, height, and CSS @page. A set format takes precedence over explicit width and height; preferCSSPageSize is false by default, so CSS page size does not automatically take priority over the requested paper size.

Content is missing or appears half-rendered

A navigation lifecycle event or network-idle condition may happen before the site has finished rendering the content you care about. Wait for a relevant selector or application-specific readiness condition before printing. Puppeteer waits for fonts by default, but that does not mean asynchronous page data is ready.

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

The browser works locally but not in deployment

Confirm which browser runtime the deployment launches. Puppeteer only guarantees compatibility with its bundled browser; a separately installed browser requires deliberate version and deployment checks.

Or skip the browser setup

If you need a PDF from a URL without managing a Puppeteer browser, ScreenshotNeo provides a website screenshot API that can return a PDF. Its features include PDF paper size, margins, landscape, and page ranges; see the API documentation for request options.

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
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

This one-call example returns an image; configure PDF output and its options using the API documentation. ScreenshotNeo accepts cookie or 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 or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response reports the page verdict and billing status in headers. Its MCP server offers take_screenshot, get_page_info, and capture_pdf for AI agents. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Sign up for free.

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.

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

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.