October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

How to Save a Webpage as PDF Using Selenium and Chrome

A practical guide to saving webpages as PDFs with Selenium’s Python WebDriver API or Chrome’s headless command line, including layout, compatibility, and troubleshooting.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To save a webpage as a PDF with Selenium and Chrome, open the page in a headless Chrome WebDriver session, call Selenium’s driver.print_page(), decode its base64 result, and write the bytes to a file. If you do not need WebDriver automation, Chrome can also print a URL directly from its headless command line.

Save a webpage as PDF with Selenium in Python

Selenium’s print-page operation prints the page currently open in the browser and returns the PDF as base64-encoded content. Decode that content before writing it to disk. Chromium printing through this WebDriver operation requires headless mode.

As an Amazon Associate I earn from qualifying purchases.

import base64
from pathlib import Path
from selenium import webdriver
from selenium.webdriver.common.print_page_options import PrintOptions

options = webdriver.ChromeOptions()
options.add_argument("--headless=new")

driver = webdriver.Chrome(options=options)
try:
    driver.get("https://example.com")
    pdf_base64 = driver.print_page(PrintOptions())
    Path("page.pdf").write_bytes(base64.b64decode(pdf_base64))
finally:
    driver.quit()
  1. Install Selenium in the Python environment you will run the script from, and ensure Chrome is installed.
  2. Set the URL in driver.get() and choose the output filename in Path("page.pdf").
  3. Run the script. It opens the URL, requests a PDF of the current page, decodes the returned data, and writes page.pdf in the current working directory.
  4. Open the PDF and check that the content and page breaks meet your needs.

The Selenium Print Page guide describes this API and its print settings. The Python WebDriver API describes driver.print_page() as making a best effort to return a PDF based on the supplied parameters; it is not a guarantee that every site’s dynamic content will be ready or included.

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

Set print layout with Selenium

Use Selenium’s PrintOptions to control print layout. The documented settings cover orientation, page ranges, paper size, margins, scale, background rendering, and shrink-to-fit. For example, configure the options 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
print_options = PrintOptions()
print_options.orientation = "landscape"

pdf_base64 = driver.print_page(print_options)
Path("page.pdf").write_bytes(base64.b64decode(pdf_base64))

Set only the properties your output requires; the available values and behavior are documented in the Selenium print-page reference. Paper size, margins, scale, and whether backgrounds print can change pagination and appearance, so inspect a generated PDF rather than assuming screen layout and print layout will match.

Use Chrome headless without Selenium

If you only need Chrome to load a URL and save a PDF—not to automate interactions or manage the browser through WebDriver—use Chrome’s command-line printing:

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)
chrome --headless --print-to-pdf https://example.com

Chrome writes output.pdf in the current working directory by default. To suppress the print header and footer, use --no-pdf-header-footer. To set a maximum wait before capture, use the documented timeout flag, for example:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
chrome --headless --print-to-pdf --no-pdf-header-footer --timeout=5000 https://example.com

The timeout value is in milliseconds; Chrome’s example uses 5000. It is a capture-time limit, not proof that every page has finished loading. Consult the Chrome Headless command-line reference for the documented flags, and check behavior against your installed Chrome version.

Rank #3
Sale
Epson Workforce ES-400 II High-Speed Color Duplex Desktop Document Scanner
  • FAST DOCUMENT SCANNING — Document scanner with feeder allows you to speed through stacks with a 50-sheet Auto Document Feeder (ADF); Efficient office scanner to help you scan more productively
  • INTUITIVE, HIGH-SPEED SOFTWARE — Quickly scan with this desktop document scanner; Epson ScanSmart Software lets you easily preview scans, email files, upload to the cloud, and more; Plus, automatic file naming saves even more time
  • SEAMLESS INTEGRATION — Easily incorporate your data into most document management software with the included TWAIN driver; Office document scanner integrates seamlessly with business workflows
  • EASY SHARING — Duplex scanner allows you to scan straight to email or popular cloud storage2 services like Dropbox, Evernote, Google Drive, and OneDrive for simple storage and sharing
  • SIMPLE FILE MANAGEMENT — Scanner allows the creation of searchable PDFs with Optical Character Recognition (OCR) and convert scans to editable Word or Excel files effortlessly; Designed for home and office document scanning

Choose Selenium or the Chrome command line

Need Selenium WebDriver Chrome headless command line
Automate browser actions before printing Use WebDriver to navigate and interact, then print the current page. Directly captures a URL; the documented command is not a WebDriver automation workflow.
Control print layout PrintOptions exposes orientation, page ranges, page size, margins, scale, background rendering, and shrink-to-fit. The referenced documentation describes flags including header/footer omission and capture timeout.
Choose how output is saved Returns base64-encoded PDF content; your code decodes and writes it to the desired path. Writes output.pdf to the current working directory by default.
Handle page readiness Your automation can wait for the site-specific content it needs before printing. --timeout sets a capture wait limit; a fixed delay is not a universal guarantee of readiness.

Wait for dynamic content before printing

A page can render its initial HTML before the content you care about appears. If the site uses client-side rendering or delayed requests, wait for a meaningful condition before calling print_page(), such as the presence of the element containing the content. The exact selector and wait condition depend on the target site; no general wait duration ensures all dynamic content, lazy-loaded assets, or personalized state will be present.

Chrome’s command-line timeout only sets the maximum wait before capture even if a page is still loading. For either approach, inspect the PDF for missing sections, incomplete images, or unexpected page breaks. If the content is absent, adjust readiness handling or print layout and generate it again.

Rank #4
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

Check Chrome and ChromeDriver compatibility

The Selenium Chrome documentation says Selenium 4 is compatible with Chrome 75 and newer and advises matching Chrome and ChromeDriver major versions. Treat that as the documentation’s compatibility guidance, not a guarantee for every current installation: check the browser and driver versions available in your environment and follow the current Selenium guidance for them.

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.

Troubleshooting

  • Printing fails in a visible Chromium session: Selenium’s print-page documentation requires Chromium to be headless for this operation. Add a headless argument to ChromeOptions, as in the example.
  • The PDF file is empty or invalid: Selenium returns encoded content, not ready-to-write PDF bytes. Decode it with base64.b64decode() before writing.
  • The script cannot start Chrome: Check that Chrome is installed and that the Chrome and ChromeDriver major versions match, as Selenium’s Chrome guide advises.
  • Content is missing from the PDF: The page may not have finished rendering the required content when printing began. Wait for a site-specific readiness condition, then print again and inspect the result.
  • The layout is wrong or pages break unexpectedly: Review orientation, paper size, margins, scale, background rendering, and shrink-to-fit in PrintOptions; generate another PDF and verify it.
  • The CLI PDF includes unwanted headers or captures too early: Use --no-pdf-header-footer to omit headers and footers, and adjust --timeout when appropriate. A timeout alone does not establish that a particular site’s content is ready.
  • The CLI output is not where expected: The documented default is output.pdf in the current working directory. Run Chrome from the intended directory or consult the installed version’s command-line behavior.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

For a direct screenshot or PDF API request, ScreenshotNeo accepts a URL in one GET request. Its clean-shot flow accepts cookie or consent banners like a visitor 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 responses include X-Page-Verdict and X-Billed headers. ScreenshotNeo also offers an MCP server with take_screenshot, get_page_info, and capture_pdf tools for AI agents and MCP clients.

For its PDF output, request the PDF format using the options documented in the ScreenshotNeo API documentation. The following one-call cURL example saves a PDF response; adapt the target URL and PDF options to the documented API parameters:

Best Value
Sale
ScanSnap iX2500 Wireless or USB High-Speed Document Scanner, Black
  • OUR MOST ADVANCED SCANSNAP. Large touchscreen, fast 45ppm double-sided scanning, 100-sheet document feeder, Wi-Fi and USB connectivity, automatic optimizations, and support for cloud services. Upgraded replacement for the discontinued iX1600
  • CUSTOMIZABLE. SHARABLE. Select personalized profiles from the touchscreen. Send to PC, Mac, mobile devices, and clouds. QUICK MENU lets you quickly scan-drag-drop to your favorite computer apps
  • STABLE WIRELESS OR USB CONNECTION. Built-in Wi-Fi 6 for the fastest and most secure scanning. Connect to smart devices or cloud services without a computer. USB-C connection also available
  • PHOTO AND DOCUMENT ORGANIZATION MADE EFFORTLESS. Easily manage, edit, and use scanned data from documents, receipts, photos, and business cards. Automatically optimize, name, and sort files
  • AVOIDS PAPER JAMS AND DAMAGE. Features a brake roller system to feed paper smoothly, a multi-feed sensor that detects pages stuck together, and skew detection to prevent paper damage and data loss
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

ScreenshotNeo’s free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. See ScreenshotNeo and sign up free for 1,000 screenshots a month with no card.

Frequently Asked Questions

Does Selenium return a PDF file from print_page()?

It returns base64-encoded PDF content. Decode the value before writing the PDF bytes to a file.

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

Can I print a webpage with Chrome without Selenium?

Yes. Chrome’s headless command-line option can print a URL directly to a PDF.

Quick Recap

Bestseller No. 4
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.

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
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

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.