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

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

Use driver.print_page() when you need a PDF of the browser’s printed page layout. Use driver.save_screenshot() when you need the pixels in the current window, then convert the resulting PNG to a PDF with a separate image/PDF library. Selenium does not turn a screenshot into a PDF merely because you give the file a .pdf extension.

This distinction matters on Windows: print-to-PDF and screenshot-to-PDF have different output, browser requirements and failure modes. The examples below use absolute Windows paths, clean up the browser reliably and show both workflows.

Choose the PDF you actually need

Requirement Use Result
A document-like PDF following the page’s print rendering driver.print_page() PDF data returned by Selenium, encoded as base64
A PDF that contains exactly the captured window image save_screenshot(), then an image/PDF conversion step PNG pixels embedded in a PDF

Browser print output and a screenshot can differ substantially. Print stylesheets, page breaks and printable colors may change the layout. A screenshot captures what was painted in the current viewport; it does not automatically become a paginated document.

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

Selenium’s documentation describes Chromium print-page support in headless mode. The screenshot API writes PNG output and recommends a full path for the filename. See the Selenium Print Page documentation, window and tab examples and the Python Chromium WebDriver API.

#1 Best Overall

Prerequisites on Windows

  • Python installed and available as python (or use the Python launcher, py).
  • Selenium installed in the environment that runs your script: py -m pip install selenium.
  • A Chromium browser (such as Chrome or Chromium) for the documented print workflow. Selenium Manager can obtain a compatible driver in many current Selenium installations, but the exact browser/driver compatibility depends on the versions installed on your machine.
  • A URL that the process can reach, and permission for Python to create the output directory and write files.

Create a project directory and run the script from there, or use absolute paths so the file is not accidentally written to an unexpected working directory.

Method 1: print the current Selenium page to a PDF

This is the direct solution when “PDF” means the browser’s rendered/printed page, not a bitmap of the window.

Complete Python example

from pathlib import Path
import base64
from selenium import webdriver

output = Path(r"C:reportspage.pdf")
output.parent.mkdir(parents=True, exist_ok=True)

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

driver = webdriver.Chrome(options=options)
try:
    driver.get("https://example.com")
    pdf_base64 = driver.print_page()
    output.write_bytes(base64.b64decode(pdf_base64))
    print(f"Wrote {output}")
finally:
    driver.quit()
  1. Path(r"C:reportspage.pdf") uses a raw string, so backslashes are not interpreted as Python escape sequences.
  2. mkdir(...) creates the destination directory if it does not already exist.
  3. The headless option is set before creating the Chromium driver, as required by Selenium’s documented Chromium print support.
  4. print_page() returns base64-encoded PDF data. Decode it and write the resulting bytes with a .pdf filename.
  5. The finally block closes the browser even if navigation or printing raises an exception.

Controlling print output

The Selenium print API accepts print options for the page representation, such as orientation, page size, margins, scale, background graphics and page ranges, depending on the Selenium version and browser implementation you have installed. Check the API documentation for the options exposed by your installed release rather than assuming every browser supports every setting. If a particular option is ignored, first verify the browser and Selenium versions, then inspect the resulting PDF.

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

Printing captures the current document state. Navigate first, wait for content that your page loads asynchronously, and interact with the page before calling print_page() when those interactions affect the output.

Method 2: capture a screenshot, then make an image PDF

Use this route when visual fidelity to the current window is more important than print pagination. Selenium’s screenshot method produces PNG data on disk; changing only the extension to .pdf does not convert it.

Save the PNG

from pathlib import Path
from selenium import webdriver

png_path = Path(r"C:reportspage.png")
png_path.parent.mkdir(parents=True, exist_ok=True)

driver = webdriver.Chrome()
try:
    driver.get("https://example.com")
    driver.save_screenshot(str(png_path))
    print(f"Wrote {png_path}")
finally:
    driver.quit()

Pass a full filename, including .png. The call captures the current browser window, so set the window size or use the appropriate headless configuration if a particular viewport is required.

Rank #2
Dell Latitude 5420 14" FHD Business Laptop Computer, Intel Quad-Core i5-1145G7, 16GB DDR4 RAM, 256GB SSD, Camera, HDMI, Windows 11 Pro (Renewed)
  • 256 GB SSD of storage.
  • Multitasking is easy with 16GB of RAM
  • Equipped with a blazing fast Core i5 2.00 GHz processor.

Convert the PNG with a separate library

Selenium documents the capture operation, not a preferred conversion package. One practical Python implementation is Pillow; install it separately with py -m pip install pillow:

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

image = Image.open(r"C:reportspage.png").convert("RGB")
image.save(r"C:reportspage.pdf", "PDF", resolution=150.0)

This creates a PDF page containing the screenshot pixels. It does not recreate selectable HTML text or the browser’s print layout. Large screenshots can produce large PDFs; reduce the image dimensions or choose an appropriate resolution only when that trade-off is acceptable.

Keep capture and conversion in one script

from pathlib import Path
from selenium import webdriver
from PIL import Image

folder = Path(r"C:reports")
folder.mkdir(parents=True, exist_ok=True)
png_path = folder / "page.png"
pdf_path = folder / "page-image.pdf"

driver = webdriver.Chrome()
try:
    driver.get("https://example.com")
    driver.save_screenshot(str(png_path))
finally:
    driver.quit()

with Image.open(png_path) as source:
    source.convert("RGB").save(pdf_path, "PDF", resolution=150.0)
print(f"Wrote {pdf_path}")

Full-page and dynamic-content considerations

A normal screenshot is a capture of the current window, not automatically an entire, infinitely scrolling document. If the page uses lazy-loaded images, scroll through the page or otherwise trigger loading before capture, then choose a capture strategy that matches your required dimensions. For print output, the browser’s pagination and print CSS determine what appears on each page.

For pages that render after JavaScript runs, wait for a meaningful condition instead of immediately printing after get(). A typical Selenium wait is:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait

WebDriverWait(driver, 30).until(
    lambda d: d.find_element(By.CSS_SELECTOR, "main")
)

Replace main with a selector that exists only when the content you need is ready. This prevents a successful-looking PDF from containing an empty shell.

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.

Windows paths, permissions and repeatable output

  • Prefer Path(r"C:reportspage.pdf") or build paths with pathlib; avoid unescaped strings such as "C:reportspage.pdf", where sequences such as r can be interpreted by Python.
  • Create the parent directory before starting the capture.
  • Ensure the account running Python can write to that directory. A protected folder can cause a permission error even when the browser loads correctly.
  • Use distinct names for concurrent jobs. Two processes writing the same PDF can overwrite one another.
  • Check Path.exists() and Path.stat().st_size after the operation when a pipeline must fail fast on missing or empty output.

Troubleshooting common failures

“The PDF is actually a PNG” or no PDF is created

save_screenshot() writes PNG. Use print_page() for browser PDF output, or convert the PNG with an image/PDF library. Do not just rename the extension.

Rank #3
HP OmniBook 3 17.3 inch Laptop PC, FHD Display, AMD Ryzen 3 30, 8 GB RAM, 512 GB SSD, AMD Radeon 610M Graphics, Windows 11 Home, Mica Silver, 17-dp0199nr
  • FULL HD IPS DISPLAY - Enjoy vibrant, crystal-clear images with 178-degree wide-viewing angles
  • AMD RYZEN 3 30 PROCESSOR - Everyday performance you can count on; Multitask, stream, game casually, and edit photos smoothly with responsive power and vibrant HDR visuals
  • ENJOY UP TO 14 HOURS AND 15 MINUTES OF BATTERY LIFE - HP Fast Charge restores battery from 0 to 50% in approximately 45 minutes
  • AMD RADEON 610M GRAPHICS - Experience smooth entertainment; Built for streaming and multitasking, enjoy realistic visuals and efficient performance for work and play
  • STORAGE AND MEMORY - 512 GB PCIe NVMe M.2 SSD offers fast speed and efficient storage; and 8 GB LPDDR5 RAM memory boosts performance with higher bandwidth

Print fails in headed Chrome

Selenium documents Chromium printing with headless mode. Add options.add_argument("--headless") before constructing the driver. If it still fails, verify that Selenium, the browser and its driver are compatible on that Windows installation.

“No such file or directory”

The parent directory does not exist, or the path was interpreted incorrectly. Create it with mkdir(parents=True, exist_ok=True) and use a raw Windows string or pathlib.

The PDF is blank or missing late content

The capture happened before JavaScript or network-loaded content finished. Wait for a page-specific element, perform required clicks or scrolling, and then call the print or screenshot method.

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

Output looks different from the visible browser

Print-to-PDF uses print rendering, which can apply print CSS and pagination. If the PDF must look like the window, capture PNG pixels and convert that image instead.

Permission or locked-file errors

Write to a directory the Python account controls, close the PDF in applications that lock files, and use a new filename for each run.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Performance and reliability choices

  • Print path: one Selenium operation returns PDF data, but page layout, fonts, print CSS and browser pagination affect the result.
  • Image path: adds a conversion step and can create larger files, but preserves the captured pixels.
  • Repeatability: fix the viewport, wait condition and URL state; dynamic ads, animations and personalized content can otherwise change captures between runs.
  • Cleanup: always call driver.quit() in finally so failed jobs do not leave browser processes running.

The Selenium documentation does not provide a complete current Windows version matrix or a guarantee that every site will render identically. Treat browser and Selenium upgrades as compatibility changes and validate representative pages after upgrading.

Rank #4
HP 14" HD Laptop, Windows 11, Intel Celeron Dual-Core Processor Up to 2.60GHz, 4GB RAM, 64GB SSD, Webcam, Dale Blue (Renewed)
  • 14” Diagonal HD BrightView WLED-Backlit (1366 x 768), Intel Graphics,
  • Intel Celeron Dual-Core Processor Up to 2.60GHz, 4GB RAM, 64GB SSD
  • 3x USB Type A,1x SD Card Reader, 1x Headphone/Microphone
  • 802.11a/b/g/n/ac (2x2) Wi-Fi and Bluetooth, HP Webcam with Integrated Digital Microphone
  • Windows 11 OS, Dale Blue

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server. One request returns a PNG, JPEG, WebP or PDF. It removes cookie/consent banners, newsletter popups and chat widgets before capture; bot checks, blank pages, timeouts, failed loads and cache hits are not billed, with the response identifying the page verdict and billing status. Its MCP server exposes take_screenshot, get_page_info and capture_pdf to Claude, Cursor and other MCP clients.

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

For the API details and all options, see the ScreenshotNeo documentation. A PDF request can be made without installing Selenium:

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

The same endpoint from Python:

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)

And Node.js:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

ScreenshotNeo supports print settings for PDFs, full-page captures, selectors, device and viewport choices, custom CSS/JavaScript, waits, cookies and headers, blocking rules, caching, signed links, asynchronous webhooks, bulk capture and a usage API. Every feature is on every plan: 1,000 shots per month are free with no card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account.

Which method should you use?

  • Choose print_page() for a browser-generated document suitable for print-style pagination.
  • Choose screenshot plus conversion when the PDF must contain the visible window as an image.
  • Choose ScreenshotNeo when you want a hosted one-call capture, consent and widget cleanup, billing only for clean shots, or MCP tools for AI agents.

Frequently Asked Questions

Can Selenium save a screenshot directly as a PDF?

No. Selenium’s screenshot method writes PNG output. Use the print API for a browser PDF, or convert the PNG with a separate library.

Does print_page() capture the whole webpage?

It produces the browser’s printed page representation. Pagination and print CSS determine how content is distributed across PDF pages; it is not the same as a pixel-perfect full-page screenshot.

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.

Why is a Windows absolute path recommended?

It avoids uncertainty about the process working directory and makes backslash escaping explicit. A raw string or pathlib path also prevents accidental escape-sequence handling.

Quick Recap

Bestseller No. 1
HP 14' HD Laptop, Windows 11, Intel Celeron Dual-Core Processor Up to 2.60GHz, 4GB RAM, 64GB SSD, Webcam, Dale Pink (Renewed)
HP 14" HD Laptop, Windows 11, Intel Celeron Dual-Core Processor Up to 2.60GHz, 4GB RAM, 64GB SSD, Webcam, Dale Pink (Renewed)
14" diagonal, 1366x768 resolution, HD BrightView LED, Glossy NON-TOUCH Display
$247.99
Bestseller No. 2
Dell Latitude 5420 14' FHD Business Laptop Computer, Intel Quad-Core i5-1145G7, 16GB DDR4 RAM, 256GB SSD, Camera, HDMI, Windows 11 Pro (Renewed)
Dell Latitude 5420 14" FHD Business Laptop Computer, Intel Quad-Core i5-1145G7, 16GB DDR4 RAM, 256GB SSD, Camera, HDMI, Windows 11 Pro (Renewed)
256 GB SSD of storage.; Multitasking is easy with 16GB of RAM; Equipped with a blazing fast Core i5 2.00 GHz processor.
$289.99
Bestseller No. 4
HP 14' HD Laptop, Windows 11, Intel Celeron Dual-Core Processor Up to 2.60GHz, 4GB RAM, 64GB SSD, Webcam, Dale Blue (Renewed)
HP 14" HD Laptop, Windows 11, Intel Celeron Dual-Core Processor Up to 2.60GHz, 4GB RAM, 64GB SSD, Webcam, Dale Blue (Renewed)
14” Diagonal HD BrightView WLED-Backlit (1366 x 768), Intel Graphics,; Intel Celeron Dual-Core Processor Up to 2.60GHz, 4GB RAM, 64GB SSD
$229.99

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.