Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk6 min

How to Scrape Web Pages with Puppeteer and Save Them as PDFs

A practical Puppeteer guide to scraping a page into PDF: choose a reliable readiness condition, configure print output, check responses, and handle common failures.

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.

Use Puppeteer to open the page in a Chromium browser, wait for the content you need, and call page.pdf(). The important choices are when the page is ready and whether the PDF should follow print or screen styling. The example below checks the navigation response, waits for a page element, saves an A4 PDF, and closes the browser even if capture fails.

Install Puppeteer and prepare a script

This example uses the Puppeteer API documented at version 25.12.0. Puppeteer versions can change, so check the documentation for the version installed in your project. The example is an illustrative combination of documented APIs; its selector and wait condition need to fit the target page.

As an Amazon Associate I earn from qualifying purchases.

In a new Node.js project, install Puppeteer:

npm install puppeteer

Save the following as scrape-to-pdf.mjs. Replace the URL and readiness selector with values appropriate for the page you are permitted to access.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import puppeteer from 'puppeteer';

const url = 'https://example.com';
const browser = await puppeteer.launch();

try {
  const page = await browser.newPage();
  const response = await page.goto(url, {
    waitUntil: 'domcontentloaded',
    timeout: 30_000,
  });

  if (response && !response.ok()) {
    throw new Error(`Page request failed: ${response.status()}`);
  }

  // Wait for the part of the page that should appear in the PDF.
  await page.locator('main').wait();

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

Run it with node scrape-to-pdf.mjs. If it completes, page.pdf() writes page.pdf to the current working directory. The Puppeteer getting-started guide shows the launch, page, navigation, and close lifecycle; its PDF API documents PDF generation and options. Puppeteer getting started · Page.pdf() method

#1 Best Overall
Sale
Epson Workforce ES-50 Compact & Lightweight Mobile Document Scanner | For Computers including PC and Mac Receipt and Document Scanner USB Powered
  • 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

Choose what counts as ready

page.goto() navigates to the URL and resolves with the main resource response after redirects. A completed navigation does not necessarily mean a JavaScript application has finished rendering the section you want to capture. Select a wait condition based on the page’s actual content rather than relying on an arbitrary pause.

Wait for a selector

The example uses page.locator('main').wait() to wait for a main-content element. Use a more specific selector when the page has several possible matches or when a particular result, article, or table must be present. Puppeteer locators wait for elements and relevant state. Page interactions

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)

Wait for a custom page condition

When an element alone is not enough, use page.waitForFunction() for a condition that reflects the content you need—for example, that a result list has at least one item. Keep the condition specific to the target site. Page.waitForFunction()

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.

Use navigation events for navigation, not application readiness

waitUntil: 'domcontentloaded' waits for the document’s DOM content-loaded event. Other navigation wait conditions are available, but no generic load event can guarantee that every site-specific, client-rendered section is ready. Combine navigation with a selector or custom condition when the printed content is populated asynchronously. Navigation options and response behavior are documented in Page.goto().

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

Set PDF output and styling deliberately

page.pdf() uses print media by default. That lets the site’s print styles determine how content is laid out and paginated. If the PDF should instead resemble the screen rendering, call await page.emulateMediaType('screen') before generating it. Puppeteer documents the media behavior in the Page class.

Common output options include:

  • path: output file path; for example, page.pdf.
  • format, or paper width and height: choose a paper size such as A4, or specify dimensions.
  • landscape: change page orientation.
  • margin: set page margins.
  • pageRanges: print selected page ranges.
  • printBackground: include background graphics. It defaults to false; enable it when colors or background images are part of the intended result.
  • scale and timeout: adjust rendering scale and the PDF operation’s timeout.
  • waitForFonts: wait for fonts before printing. The documented default is true; Puppeteer notes this may require bringing a background page to the front.

Review the complete, version-specific PDFOptions interface when you need less common settings. Print CSS, paper dimensions, margins, and background printing can all affect pagination and appearance; generate a sample and inspect it rather than assuming screen layout will carry over unchanged.

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

Check the response and close the browser reliably

A navigation completing is not the same as the requested page succeeding. The example checks response.ok() when Puppeteer returns a response, so an HTTP error status is surfaced before PDF generation. The API documents cases where page.goto() returns null, so the check is conditional. Page.goto()

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

The try/finally ensures the browser is closed whether navigation, readiness checks, or PDF generation succeeds or throws. If you build a long-running scraper, manage browser and page lifecycles intentionally rather than leaving launched browsers open after failures.

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
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Respect site access rules

Only collect pages you are allowed to access, and consider the site’s terms and applicable restrictions. A robots.txt file provides crawler guidance, but it does not itself grant permission: the IETF’s RFC 9309 says, “These rules are not a form of access authorization.” Read the RFC 9309 Robots Exclusion Protocol and assess access authorization separately.

Common problems and fixes

  • The PDF is missing dynamically rendered content: Navigation may have completed before the app filled in the desired section. Wait for a selector representing that content, or use page.waitForFunction() for a meaningful page-specific condition.
  • The script reports an HTTP failure: Inspect the status surfaced by the navigation response. Confirm that the URL is correct and that the page is available to your browser session; do not treat navigation completion alone as a successful response.
  • Background colors or images are absent: printBackground defaults to false. Set it to true if the PDF should include them.
  • The PDF differs from the screen: PDF generation uses print media by default. Check the site’s print styles; use page.emulateMediaType('screen') first only if screen styling is what you want.
  • Text wraps or pages break unexpectedly: Check the paper format, orientation, margins, scale, and print CSS. These choices affect layout and pagination.
  • Fonts appear different: Puppeteer’s documented waitForFonts default is true. If you changed that option, restore it or explicitly wait for the fonts needed by the page.
  • The browser remains running after an error: Put browser closure in a finally block so cleanup runs on both success and failure.

Or skip the browser setup

If you want a screenshot or PDF through an HTTP request instead of managing a local browser, ScreenshotNeo is a website screenshot API and MCP server for developers. Its API accepts a URL in one GET request and can return an image or PDF. See the ScreenshotNeo website and API documentation.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.pdf

For this call, use the documented output settings for PDF in the API documentation. ScreenshotNeo accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; those steps can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and responses indicate the page verdict and billing status in headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents and MCP clients. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots.

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

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

Frequently Asked Questions

Does Puppeteer save a PDF as soon as the page navigation finishes?

Not necessarily. A page can continue rendering application content after navigation, so wait for the specific content you need before calling page.pdf().

Can I save only some pages of the PDF?

Yes. Puppeteer’s PDF options include pageRanges; consult the PDFOptions interface for the syntax supported by your installed version.

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.

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
Crashes, No Sound, or Screen Glitches?Free driver scan

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.