Use Selenium’s WebDriver print-page command when you need to automate or prepare a page before saving it: Chrome must run headlessly, and Selenium returns the PDF as base64-encoded data that your script decodes and writes to a file. If you only need to print a URL without browser automation, Chrome’s headless command-line option can write the PDF directly.
Save the current webpage as a PDF with Selenium
The Python example below opens a page in headless Chrome, prints the current page, decodes Selenium’s base64 result, and writes the PDF bytes to page.pdf in the script’s current working directory. It uses Selenium 4’s documented driver.print_page() API.
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()
- Install Selenium in the Python environment running the script:
python -m pip install selenium. - Replace
https://example.comwith the page to capture. - Run the script. Selenium Manager may configure a compatible driver automatically; if driver setup fails, check the installed Chrome and ChromeDriver versions.
- Look for
page.pdfin the process’s current working directory. Change thePath("page.pdf")value to an absolute path or another destination as needed.
Selenium documents that print_page() returns the current page as base64-encoded PDF content, which is why the example decodes the return value before writing it. Its Python API describes the method as making a best effort to return a PDF for the supplied parameters.
Set print layout and page range
Pass a Selenium PrintOptions object to print_page() to control print output. The documented options include orientation, page ranges, paper size, margins, scale, background rendering, and shrink-to-fit. For example, add settings before calling driver.print_page(print_options):
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
print_options = PrintOptions()
print_options.orientation = "landscape"
print_options.background = True
pdf_base64 = driver.print_page(print_options)
Set only the properties your output requires, and consult Selenium’s current Print Page documentation for the supported property names and accepted values. Print settings affect pagination and appearance: a landscape page, altered margins, or scaling can change where content breaks across PDF pages.
Wait for page content before printing
driver.get() reaching a page does not guarantee that every site-specific dynamic element, lazy-loaded image, or personalized state is ready for printing. If the PDF is missing content, wait for a meaningful element or condition from the page before calling print_page(). The right wait depends on the site; a fixed delay alone cannot guarantee that a particular page has finished rendering.
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
After saving, open the PDF and inspect the pages, images, and page breaks. Selenium’s print documentation describes the printing API and options, not a universal guarantee that every page’s dynamic content will be present.
Use Chrome headless directly when Selenium is unnecessary
If you do not need to interact with the page through WebDriver, Chrome can print a URL from the command line:
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
chrome --headless --print-to-pdf https://example.com
Chrome saves output.pdf in the current working directory by default. To omit Chrome’s print header and footer, use --no-pdf-header-footer. To set a capture wait limit, Chrome documents --timeout=5000, with the value in milliseconds; the page may still be loading when capture proceeds. Check the flags supported by your installed Chrome release in the Chrome Headless command-line reference.
Choose Selenium or the Chrome command line
| Need | Selenium WebDriver | Chrome headless command line |
|---|---|---|
| Automate or prepare a page before printing | Use a WebDriver session to navigate and interact, then print the current page. | Captures a URL directly; the documented command does not provide WebDriver interaction. |
| Control print layout | PrintOptions supports orientation, page ranges, size, margins, scale, background, and shrink-to-fit. |
The cited command-line documentation describes switches including header/footer omission and capture timeout. |
| Handle the resulting file | Decode the returned base64 data and write the PDF where your application needs it. | Chrome writes a PDF file directly; the default name is output.pdf. |
| Control readiness | Wait in your automation for the page condition you need before printing. | --timeout sets a wait limit, but does not establish that every site-specific resource is ready. |
Compatibility and troubleshooting
Chrome will not start or WebDriver reports a session error
Check the versions of Chrome and ChromeDriver. Selenium’s Chrome guide says Selenium 4 is compatible with Chrome 75 and newer and advises matching Chrome and ChromeDriver major versions. These are Selenium’s documented compatibility guidance; confirm the requirements and installed versions in your environment. See the Selenium Chrome documentation.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
Printing fails in a visible browser
Selenium’s print-page guide says Chromium printing requires headless mode. Start Chrome with a headless argument such as --headless=new, as in the example.
The PDF is blank or lacks late-loading content
Wait for the specific content your workflow needs before printing, rather than assuming navigation alone means the page is ready. Check whether the page requires interaction, authentication, or additional time to render, then inspect the resulting PDF. A command-line timeout is only a timing control, not a guarantee of complete rendering.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
The file is not where expected
Relative paths are resolved from the process’s current working directory, which may differ from the script’s folder. Print or inspect that directory, or write to an absolute path. The Chrome command-line route likewise defaults to output.pdf in its current working directory.
Or skip the browser setup
If your goal is to request a webpage PDF rather than automate Chrome locally, ScreenshotNeo offers a one-request API. It is a website screenshot API and MCP server for developers. The request below asks for a PDF; see the ScreenshotNeo API documentation for the PDF parameter details.
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 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 response headers identify the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents using Claude, Cursor, or another MCP client. The free plan includes 1,000 shots a 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.
Recommended Free Tools
Frequently Asked Questions
Does Selenium save the PDF file automatically?
No. Selenium returns base64-encoded PDF data; decode it and write the resulting bytes to a file.
Can Selenium print a page in a regular visible Chrome window?
The documented Selenium print-page operation requires Chromium to run headlessly.
Quick Recap
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.

