Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober 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 desk5 min

HTML to PDF with Selenium and ChromeDriver

Use Selenium’s print-page command in headless Chrome, decode its PDF response, and write a file. Learn the key layout controls, compatibility checks, and Chrome CLI alternative.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Selenium’s WebDriver print-page command to turn the page currently open in headless Chrome into a PDF. Selenium returns encoded PDF data rather than saving a file for you, so decode that result and write it as binary. This guide uses Python, then shows the print settings, setup checks, and a direct Chrome alternative.

Print a rendered page with Selenium in Python

The example below navigates to a URL, enables headless Chrome, calls Selenium’s print-page API, decodes its base64 result, and saves page.pdf. Install Selenium with python -m pip install selenium; use a current Chrome or Chrome for Testing installation.

As an Amazon Associate I earn from qualifying purchases.

import base64
from pathlib import Path

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.print_page_options import PrintOptions

url = "https://example.com"

options = Options()
options.add_argument("--headless=new")

with webdriver.Chrome(options=options) as driver:
    driver.get(url)

    print_options = PrintOptions()
    print_options.orientation = "portrait"
    print_options.background = True

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

print("Saved page.pdf")

The output is created in the process’s current working directory. Change the path in write_bytes to choose another location. The example enables backgrounds; remove that setting if you do not want printed background colors or images. Selenium’s API describes printing as best effort, not a guarantee of identical results across pages or environments. (Selenium Print Page; Python Chromium WebDriver API)

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

Wait for page content before printing

driver.get() waits according to WebDriver’s page-load strategy, but a site may populate content later with JavaScript. If you need a particular element, wait for it explicitly before calling print_page:

#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
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

WebDriverWait(driver, 20).until(
    EC.visibility_of_element_located((By.CSS_SELECTOR, "main"))
)

Place this inside the with block after driver.get(url). Choose a selector that indicates the content you actually need; visibility of one element cannot prove that every image, font, or asynchronous section has finished loading.

Adjust the PDF layout

Selenium’s PrintOptions supports orientation, page ranges, paper dimensions, margins, scale, background printing, and shrink-to-fit. Set only what the document needs and check the generated file: print CSS and page content affect the result.

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)
  • Orientation: use portrait for typical documents or landscape for wide tables and dashboards.
  • Paper size: select a standard size such as A4 when the page should fit a known paper format.
  • Margins: set top, bottom, left, and right margins when content is too close to an edge or needs more printable area.
  • Scale and shrink-to-fit: adjust when text or wide elements are clipped or unexpectedly small.
  • Page ranges: request selected pages, for example pages 2–4, when a full document is not needed.
  • Backgrounds: turn background colors and images on when they carry information or are part of the intended layout.

Property names and accepted forms are binding-specific. Consult the Selenium print-page examples for your language rather than assuming Python syntax applies to Java or JavaScript.

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

Use Chrome headless without Selenium

If you only need to open a URL and save a PDF, Chrome’s headless command line avoids writing WebDriver code. Run the Chrome executable available on your system:

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

Chrome documents --no-pdf-header-footer to omit the print header and footer. It also documents --timeout to bound the wait before capture and --virtual-time-budget to advance time-dependent page behavior. Those timing options can help with delayed content, but a fixed wait does not ensure every dynamic site has finished rendering. See the Chrome Headless command-line reference.

Keep Chrome and ChromeDriver compatible

Selenium uses Selenium Manager by default in its bindings to help manage browser and driver setup. For Chrome-specific setup, Selenium’s documentation says Selenium 4 is compatible with Chrome v75 and greater and advises matching Chrome and ChromeDriver at least by major version. Avoid copying an old fixed driver version into a new project; browser releases change. (Selenium documentation; Selenium Chrome documentation)

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

For Chrome 115 and newer, Chrome and ChromeDriver releases are integrated through Chrome for Testing. Use its availability dashboard or JSON endpoints to obtain matching versions. If using a non-CfT Chrome binary, ChromeDriver’s guidance describes matching by the browser’s MAJOR.MINOR.BUILD version, with a milestone fallback where needed. Recheck the current guidance when setting up a build or updating a browser. (ChromeDriver version selection; Chrome for Testing downloads)

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

ChromeDriver is the standalone server Selenium uses to control Chrome and implements W3C WebDriver and WebDriver BiDi standards. Chrome for Testing supplies versioned browser and matching driver binaries for automation environments. (What is ChromeDriver?; Chrome for Testing binaries)

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

Troubleshoot common PDF failures

  • Chrome fails to start: verify Chrome is installed and available to Selenium Manager, or configure the browser binary and driver for your environment. Check that the installed Chrome and ChromeDriver major versions match.
  • The PDF file is empty or invalid: make sure you decoded Selenium’s returned base64 data and wrote bytes, not the encoded text, to the file.
  • Content is missing: wait for a page-specific element or known loading condition before printing. A page-load completion does not establish that all asynchronous content is ready.
  • Content is clipped or too small: inspect paper size, orientation, margins, scale, and shrink-to-fit; also check whether the page’s print styles alter its layout.
  • Background graphics are absent: enable the print option for backgrounds and confirm that the page itself supplies those backgrounds.
  • Output differs between machines: Selenium calls print-page best effort. Compare the browser versions, page state, loaded resources, fonts, and print settings rather than expecting pixel-identical output by default.
  • Headless CLI captures too early: adjust Chrome’s documented timeout or virtual-time budget for the page’s behavior, then inspect the output; a longer wait is not a universal completion signal.

Or skip the browser setup

ScreenshotNeo is a website screenshot API that also returns PDFs. Its one-call endpoint can be used when you do not need Selenium navigation or interaction before capture:

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

See the ScreenshotNeo API documentation for options and response details. Cookie banners are accepted and removed before capture, along with known newsletter popups and chat widgets; those steps can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and response headers report the page verdict and billing status. Its MCP server gives AI agents tools for screenshots, page information, and PDF capture. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Sign up for the free plan.

Choosing between Selenium and the Chrome CLI

Use Selenium when the workflow needs WebDriver navigation, page interaction, or structured print options before output. Use Chrome’s headless CLI when a URL-to-file command is sufficient. In either case, inspect PDFs from the pages and browser environments that matter to your application; the official Selenium API characterizes PDF generation as best effort.

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

Frequently Asked Questions

Does Selenium save the PDF file automatically?

No. The print-page call returns encoded PDF data; decode it and write the resulting bytes to a file.

Can I print only selected pages?

Yes. Selenium print options include page ranges; syntax varies by language binding.

Does Selenium’s print-page command work in headed Chrome?

Selenium’s browser windows and tabs guide specifies that the print-page operation requires Chromium to run headlessly.

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
Outdated Drivers Are Slowing You DownFree scan - exact matches
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.