Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk5 min

How to Generate PDFs with ChromeDriver After a Page Loads

Navigate with Selenium, wait for the page content you need, then save ChromeDriver’s current-page PDF. Includes CDP, Headless Chrome, and troubleshooting options.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Selenium to open the page, wait for the content you need to appear, then call ChromeDriver’s print_page() and save the returned PDF. Selenium’s navigation wait ends when the page’s onload event fires; it does not guarantee that later scripts, lazy-loaded content, or application data have finished rendering.

Generate a PDF with Selenium and ChromeDriver

This Python example waits for a page-specific element before printing. Replace the URL and selector with a meaningful part of the page you expect to include. Install Selenium with python -m pip install selenium and ensure Chrome and a compatible ChromeDriver are available in your environment.

As an Amazon Associate I earn from qualifying purchases.

from pathlib import Path
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

url = "https://example.com"
ready_selector = "main"

options = webdriver.ChromeOptions()
# Uncomment for a headless browser:
# options.add_argument("--headless")

driver = webdriver.Chrome(options=options)
try:
    driver.get(url)
    WebDriverWait(driver, 30).until(
        EC.visibility_of_element_located((By.CSS_SELECTOR, ready_selector))
    )
    pdf_base64 = driver.print_page()
    import base64
    Path("page.pdf").write_bytes(base64.b64decode(pdf_base64))
finally:
    driver.quit()

In Selenium Python 4.32.0, print_page() returns a string containing the PDF data, so decode it before writing a binary PDF file. The Selenium Chrome WebDriver API documentation describes get(), print_page(), and execute_cdp_cmd().

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

Wait for the right page state

driver.get(url) waits for the browser’s page-load event. A page can continue rendering after that point, so tie the print operation to the content that matters rather than assuming navigation completion means the PDF is ready.

#1 Best Overall
Brother DCP-L2640DW Wireless Compact Monochrome Multi-Function Printer, Copy, Scan, Duplex, Mobile Printing
  • BEST FOR SMALL BUSINESSES – Engineered for extraordinary productivity, the Brother DCP-L2640DW Monochrome (Black & White) 3-in-1 combines laser printer, scanner, copier in one compact footprint and delivers high-quality black & white prints
  • FAST PRINTER WITH EFFICIENT SCANNING – Produces documents quickly with print speeds up to 36 ppm(2) and scan speeds up to 23.6/7.9 ipm(3) (black/color). A 50-page auto document feeder(4) allows for convenient, time saving multi-page scanning and copying
  • FLEXIBLE CONNECTION OPTIONS – Easily navigate the changing demands of your business with secure multi-device connectivity via built-in dual-band wireless (2.4GHz / 5GHz) and Ethernet. Or connect locally to a single computer via USB interface
  • BROTHER MOBILE CONNECT APP – Print, scan, and manage your wireless printer anytime, from almost anywhere from your mobile device. Order Brother Genuine Supplies, track toner usage, and complete more work on-the-go(5)
  • CHOOSE BROTHER GENUINE TONER – When it’s time to replace your toner, be sure to choose Brother Genuine TN830 or TN830XL replacement toner. And with Refresh EZ Print Subscription Service, you’ll never worry about running out of toner again and you’ll enjoy savings of up to 50%(6) on Brother Genuine Toner. Get started with Refresh today with a Free Trial(1)

Wait for a useful element

The sample waits for a visible CSS selector. Choose an element that appears only when the relevant content is ready—for example, the report container or a results table. If the element appears before its data is populated, wait for a stronger condition, such as a known status changing or expected text becoming visible.

Use a delay only as a fallback

If the page offers no reliable readiness signal, a fixed wait can help, but it is a timing heuristic: slow runs may still print too early, while fast runs waste time. Selenium’s page-load timeout limits navigation waiting; it is not a signal that asynchronous page content is ready.

Rank #2
Brother HL-L2405W Wireless Compact Monochrome Laser Printer with Mobile Printing, Black & White Output | Includes Refresh Subscription Trial(1), Works with Alexa
  • BEST FOR HOMES & HOME OFFICES – Engineered for consistent, premium print quality, the Brother HL-L2405W Monochrome (Black & White) Laser Printer delivers sharp, crisp prints at an affordable price. Prints one-sided documents at speeds up to 30ppm(2)
  • COMPACT, CONNECTED PRINTER – Flexible connection options make this an ideal printer for home use and at-home offices. Securely connect to multiple devices with built-in dual-band wireless (2.4GHz/5GHz) or locally to a single computer via USB interface
  • BROTHER MOBILE CONNECT APP – Manage your printer remotely and print from your mobile device anytime, from almost anywhere. Order Brother Genuine Supplies, track toner usage, and complete more work on-the-go(3)
  • VERSATILE PAPER HANDLING – Enjoy seamless, reliable everyday printing with the 250-sheet paper tray(4) and a manual feed slot that enables printing on envelopes and specialty pape
  • BROTHER IS AT YOUR SIDE – Backed by Brother with a 1-year limited warranty and free online, call, or live chat support for the life of your printer

Choose a PDF generation route

Route Best suited to Synchronization and control
Selenium print_page() A workflow already using Selenium that needs a PDF of the current page Navigate, wait for application-specific readiness, then print. The API describes the output as a best effort based on parameters.
Chrome DevTools Protocol Page.printToPDF A Chrome-specific workflow that needs the protocol print command or its parameters Issue it only after the page reaches the desired state; match parameters to the browser and protocol version.
Chrome Headless --print-to-pdf Direct URL-to-PDF output without Selenium interactions Prints after loading by default; --timeout specifies a delayed capture time, not proof that content has finished loading.

The Chrome DevTools Protocol documents the Page domain, including Page.printToPDF. Selenium’s Chrome driver also exposes execute_cdp_cmd() to issue CDP commands. Consult the protocol reference for the exact parameters available to your browser version.

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

Use Chrome Headless for a direct URL capture

When you do not need Selenium to interact with the page, Chrome Headless can print a URL directly:

Rank #3
Sale
Canon imageCLASS LBP6030w - Monochrome Single-Function Wireless Compact Wireless Laser Printer, 1 Year Limited Warranty, 19 PPM, White - Print Only
  • FAST PRINT SPEEDS: Print up to 19 pages per minute.
  • COMPACT DESIGN: Space-saving, compact design fits anywhere in your home, school or small office.
  • WIRELESS CONNECTIVITY: Print from almost anywhere in your workspace using your compatible mobile device.
  • PAPER CAPACITY: Up to 150 sheets.
  • SUSTAINABILITY: Uses less than 2 watts in Energy Saver mode.
chrome --headless --print-to-pdf=output.pdf https://example.com

Chrome’s Headless command-line reference documents --print-to-pdf, --timeout, and --no-pdf-header-footer. For example, add --no-pdf-header-footer to omit Chrome’s generated print header and footer. The documentation notes that an older Chrome version may require the legacy alias --print-to-pdf-no-header; check the flag supported by the version you run.

Check the PDF before relying on it

PDF creation does not guarantee that a particular site will render faithfully. Inspect the output for the expected text, page count, orientation, background colors, and print styling. Web pages can apply print-specific CSS, and content that has not loaded by the time of capture will not appear.

Rank #4
Brother HL-L2460DW Wireless Compact Monochrome Laser Printer with Duplex, Mobile Printing, Black & White Output | Includes Refresh Subscription Trial(1), Works with Alexa
  • BEST FOR HOME OFFICES & SMALL TEAMS – Engineered for consistent, premium print quality, the Brother HL-L2460DW Monochrome (Black & White) Laser Printer produces documents that are clear, crisp, and easy to review and share, all at an affordable price
  • COMPACT, CONNECTED, EXCEPTIONALLY EFFICIENT– Connect with built-in dual-band wireless (2.4GHz/5GHz), Ethernet, or to a single computer via USB interface. Prints at speeds up to 36ppm(2), plus automatic duplex printing saves time and reduces paper waste
  • BROTHER MOBILE CONNECT APP – Manage your wireless printer remotely and print from your mobile device anytime, from almost anywhere. Order Brother Genuine Supplies, track toner usage, and complete more work on-the-go(3)
  • VERSATILE PAPER HANDLING – Tackle high-volume black & white printing with the 250-sheet capacity paper tray.(4) The manual feed slot enables printing on envelopes and specialty paper
  • BROTHER IS AT YOUR SIDE – Backed by Brother with a 1-year limited warranty and free online, call, or live chat support for the life of your printer
  • Confirm the expected content is present, especially data rendered after navigation.
  • Check page breaks, margins, and orientation in the resulting PDF.
  • Check whether the site’s print styles hide or alter content you need.
  • Review whether background graphics and colors appear as required.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common failures

The PDF is blank or missing dynamic content

The capture may have happened after the load event but before the application finished rendering. Wait for a content-specific element or state. If using Chrome Headless, a --timeout can delay capture, but Chrome may still capture while the page is loading.

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

Navigation times out

A page-load timeout concerns navigation, not the readiness of every component. Check the URL and network access, and set an appropriate page-load timeout for slow sites. Once navigation succeeds, use a separate explicit wait for the content you need.

Best Value
HP LaserJet M110w | Monochrome | Laser Printer | Fast Black-and-White Printing | Mobile Printing | Wireless Printing | Fast Printing
  • FROM AMERICA'S MOST TRUSTED PRINTER BRAND – Perfect for small teams printing professional-quality black & white documents and reports. Perfect for 1-3 people
  • WORLD'S SMALLEST LASER IN ITS CLASS – Precision laser printing that fits anywhere
  • FAST PRINT SPEEDS – Up to 21 black-and-white pages per minute single-sided
  • WIRELESS WITH SELF-RESET – Helps you stay connected
  • PRINT FROM ANY DEVICE – Wireless printing from any mobile device, PC or tablet. Works with Microsoft, Mac, AirPrint, Android, Chromebook and more

The PDF file cannot be opened

With Selenium’s Python print_page(), decode the returned base64 string and write the result in binary mode, as in the example. Writing the encoded text directly as though it were PDF bytes produces an invalid file.

Chrome rejects a PDF flag

Command-line options can differ across Chrome versions. The Headless documentation identifies --no-pdf-header-footer and notes the older --print-to-pdf-no-header alias for previous versions. Check the documentation and installed browser version rather than assuming every flag is interchangeable.

Print output differs from the browser view

Printing uses the page’s print behavior and may paginate or style content differently from the screen. Inspect the PDF and the site’s print CSS; the documented generation methods do not promise pixel-identical output for every page.

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

Or skip the browser setup:

If you need a screenshot or PDF through an API rather than a locally managed ChromeDriver session, ScreenshotNeo accepts a URL in one GET request. Its PDF output is an alternative capture route, not a guarantee that a website’s print layout will match Chrome’s print-to-PDF output.

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

See the ScreenshotNeo documentation for request options. It can accept cookie/consent banners and remove more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks, blank pages, failed loads, timeouts, 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. The free plan includes 1,000 shots a month with no card; paid plans start at $5 for 3,000 shots.

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

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
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.