Use Selenium’s Chrome WebDriver to open the page in headless Chrome, wait for the content you need, call driver.print_page(), and decode its base64 result into a PDF file. This is a supported workflow, but the output is best effort: dynamic content, fonts, page breaks, and browser differences can affect the result.
Save the current webpage as a PDF with Selenium
Install Selenium for Python, then run this script. Selenium Manager handles browser-driver setup in most supported cases; the installed Chrome and ChromeDriver still need compatible major versions.
python -m pip install -U selenium
import base64
from pathlib import Path
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
options = webdriver.ChromeOptions()
options.add_argument("--headless=new")
driver = webdriver.Chrome(options=options)
try:
driver.get("https://example.com")
WebDriverWait(driver, 20).until(
lambda d: d.execute_script("return document.readyState") == "complete"
)
pdf_base64 = driver.print_page()
Path("page.pdf").write_bytes(base64.b64decode(pdf_base64))
finally:
driver.quit()
Replace https://example.com with the webpage URL. The output file, page.pdf, is written to the script’s current working directory. print_page() prints the page currently loaded in the WebDriver session and returns PDF data encoded as base64; decode it before writing bytes to disk. See Selenium’s print-page guide and Python WebDriver API.
Wait for the content, not just navigation
The example waits until the document’s readyState is complete. That is a useful baseline, not proof that a single-page application, delayed API response, animation, or lazy-loaded image has finished rendering. Wait for the specific element or state that matters to your page:
#1 Best Overall
- 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)
WebDriverWait(driver, 20).until(
lambda d: d.find_element("css selector", ".report-content").is_displayed()
)
Change .report-content to a selector that represents the content you need. Selenium’s print documentation does not prescribe one universal readiness condition; choose a page-specific wait where content arrives asynchronously.
Always close the browser
The finally block calls driver.quit() even if navigation, printing, decoding, or file writing raises an exception. This shuts down the browser and driver executable instead of leaving processes behind.
Rank #2
- Wireless 3-in-1: Print | Copy | Scan
- Print up to 30 Pages Per Minute (BW, Letter)
- First Print Out in Approximately 5.3 Seconds (Letter)
- Auto 2-sided Printing
- Uses Toner 071 / 071 High-Capacity Toner
Choose a PDF printing route
| Route | Use it when | What to know |
|---|---|---|
Selenium print_page() |
Your WebDriver has already opened the page and its built-in print options are sufficient. | It keeps capture in the Selenium workflow and returns PDF data that you save locally. Selenium print-page guide |
Chrome DevTools Protocol Page.printToPDF |
You need explicit print settings that the basic Selenium method does not expose. | Protocol options include orientation, paper dimensions, margins, scale, page ranges, headers and footers, CSS page-size preference, and print backgrounds. Confirm support against the installed browser version. Page domain protocol reference |
| Chrome headless command line | The page can be opened directly and does not require Selenium interactions. | Chrome supports --headless --print-to-pdf and a flag to suppress its default header and footer. Its --timeout is a maximum wait before capture, not confirmation that an application has finished rendering. Chrome Headless command-line reference |
Use WebDriver when you must sign in, click controls, set browser state, or otherwise interact with the page before printing. If none of that is needed, the command-line route may be simpler.
Set print options with Chrome DevTools Protocol
When you need finer control, Selenium Python’s execute_cdp_cmd(cmd, cmd_args) can call Chrome’s Page.printToPDF. For example, this requests landscape output, includes background graphics, and saves the returned PDF bytes:
Rank #3
- FROM AMERICA'S MOST TRUSTED PRINTER BRAND – Perfect for small teams printing, scanning and copying professional-quality black & white documents and reports. Perfect for 1-3 people
- WORLD'S SMALLEST LASER IN ITS CLASS – Precision laser printing, scanning, and copying 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
- EASILY COPY ID CARDS AND MORE – Copy both sides of ID cards or other small-size documents onto the same side of one sheet of paper
import base64
from pathlib import Path
result = driver.execute_cdp_cmd(
"Page.printToPDF",
{
"landscape": True,
"printBackground": True,
"preferCSSPageSize": True,
"marginTop": 0.4,
"marginBottom": 0.4,
"marginLeft": 0.4,
"marginRight": 0.4,
},
)
Path("page.pdf").write_bytes(base64.b64decode(result["data"]))
Run this after navigating and waiting for the page, in place of driver.print_page(). The example uses inch-based margin values as accepted by the protocol. Other documented parameters include paper width and height, scale, page ranges, header/footer templates, and CSS page-size preference. Parameter behavior can depend on the Chrome version, so consult the live protocol reference and verify the output from your installed browser.
Check the PDF and troubleshoot common failures
Selenium describes PDF printing as best effort, not a guarantee of identical output on every page or system. Open the generated file and check pagination, clipping, missing content, fonts, and backgrounds in the environment where the script will run.
Rank #4
- FROM AMERICA'S MOST TRUSTED PRINTER BRAND – Perfect for offices printing, scanning and copying black & white brochures, business documents and presentations. Perfect for 1-5 people
- FASTEST TWO-SIDED PRINTING IN ITS CLASS – Up to 28 black-and-white pages per minute single-sided. Quickly finish multipage print projects with the fastest in-class two-sided printing speed
- DUAL-BAND WI-FI WITH SELF-RESET – Automatically detects and resolves connectivity issues
- STRONG SECURITY – Built-in security features help protect your printer from potential attacks
- PRINT FROM ANY DEVICE – Wireless printing from any mobile device, PC or tablet. Ethernet included. Works with Microsoft, Mac, AirPrint, Android, Chromebook and more.
| Symptom | Likely cause | Fix |
|---|---|---|
| Content is missing or a section is blank | The document finished loading before the application’s data or target element was ready. | Wait for a page-specific element or application state before printing; increase the timeout only if the content genuinely takes longer. |
| Lazy images are absent | Images have not been loaded because they are below the viewport or load only as the page is scrolled. | Scroll through the page or trigger the site’s image-loading behavior, then wait for the relevant images before printing. |
| Chrome fails to start a session | Chrome and ChromeDriver have incompatible major versions, or browser setup is incomplete. | Check the installed versions and align their major versions. Selenium Manager handles setup in most supported cases; see Selenium’s Chrome guidance. |
| PDF dimensions, margins, or page breaks are wrong | Browser defaults or page CSS differ from the desired output. | Use Page.printToPDF to set paper dimensions, margins, scale, orientation, page ranges, or CSS page-size preference; test the resulting file. |
| Background colors or images disappear | Print backgrounds are not enabled, or the page styles backgrounds differently for print. | Set printBackground: True through the DevTools Protocol and inspect the page’s print styling. |
| Headers or footers appear unexpectedly | Chrome’s default print header/footer is enabled. | Use the relevant protocol options or Chrome CLI flag to disable defaults, and confirm the installed version’s behavior. |
Or skip the browser setup:
ScreenshotNeo can return a webpage as a PDF from one GET request, without setting up Chrome and WebDriver. See the ScreenshotNeo API documentation for options.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
For a PDF response, request PDF output using the documented API options. ScreenshotNeo removes cookie banners, newsletter popups, and chat widgets before capture; each cleanup 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 Claude, Cursor, and other MCP clients. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 shots. Learn about ScreenshotNeo or sign up for 1,000 free screenshots a month with no card.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Clear out junk files and repair common Windows errors3Fix the driver behind crashes, sound loss and screen glitchesFrequently asked questions
Does Selenium need a visible Chrome window?
No. Add --headless=new to Chrome’s startup arguments to run without a visible browser window.
Best Value
- FROM AMERICA'S MOST TRUSTED PRINTER BRAND – Perfect for small teams printing professional-quality black-and-white documents and reports. Print speeds up to 35 ppm black.
- PROFESSIONAL PRODUCTIVITY – Proficiency with every print—bring your business to life with toner designed for sharp, professional-quality prints
- UPGRADED FEATURES – Fast printing, scanning and copying, auto 2-sided printing, a 250-sheet input tray and 50-sheet auto document feeder
- AWARD-WINNING RELIABILITY – Performance you can count on page after page, and always ready for the high demands of business
- WIRELESS PRINTING – Stay connected with our most dependable Wi-Fi, which looks for the best connection to stay online
Does the saved file contain the entire webpage?
Printing produces a paginated PDF, not a single tall screenshot. Check page breaks and clipping; print layout and page CSS affect what appears on each sheet.
Can I use this for a page that requires interaction?
Yes. Navigate and perform the required WebDriver actions first, wait for the target content, and then print the current page.
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.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →

