Recommended Free Tools
To generate a PDF from the page Selenium has rendered, navigate to the URL, call Selenium’s print-page API, decode the returned Base64 string, and write the bytes to a .pdf file. In Python, the essential call is driver.print_page(print_options). This prints the current DOM as a PDF representation; it does not download a PDF that a server is already hosting.
Generate a PDF from the current page in Python
The following follows Selenium’s documented print-page flow. It starts Chrome in headless mode, opens a page, prints it, decodes the Base64 response, and saves page.pdf. See Selenium’s Print Page documentation and the browser example at Working with windows and tabs.
from base64 import b64decode
from selenium import webdriver
from selenium.webdriver.common.print_page_options import PrintOptions
options = webdriver.ChromeOptions()
options.add_argument("--headless")
driver = webdriver.Chrome(options=options)
try:
driver.get("https://example.com")
print_options = PrintOptions()
pdf_base64 = driver.print_page(print_options)
with open("page.pdf", "wb") as output:
output.write(b64decode(pdf_base64))
finally:
driver.quit()
Install Selenium with pip install selenium, and ensure a compatible Chromium browser and driver are available. Selenium Manager can resolve drivers in many current installations, but your CI image still needs a browser. The returned value is text containing Base64-encoded PDF data, so decode it before opening the destination in binary mode.
Wait until the page is ready
driver.get() waits for the browser’s normal page-load condition, but JavaScript applications may continue rendering afterward. Use an explicit wait for the content that must appear in the PDF.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →#1 Best Overall
- INNOVATIVE CARTRIDGE-FREE PRINTING — No more dealing with lots of tiny ink cartridges; With this wireless document and photo printer each ink bottle set is equivalent to about 90 individual cartridges²
- LESS FREQUENT INK REPLACEMENT — Replacement ink bottles don't have to be changed nearly as often as ink cartridges¹; When you choose this combination printer, scanner and copier you can print up to 4,500 pages black/7,500 color³
- COLOR PRINTING — Up to 2 years of ink in the box4 (and with every replacement ink set) for fewer out-of-ink frustrations
- ZERO CARTRIDGE WASTE — By using an Epson EcoTank printer you can help reduce the amount of cartridge waste ending up in landfills
- HOME PRINTER DESIGNED FOR RELIABILITY — The Epson EcoTank ET-2800 All-in-One Supertank Color Printer creates vivid, detailed prints and documents thanks to Micro Piezo Heat-Free Technology; Fire off 10 ISO pages per minute1 to easily finish large jobs
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# after driver.get(...)
WebDriverWait(driver, 30).until(
EC.visibility_of_element_located((By.CSS_SELECTOR, "main.report"))
)
For charts, images, or fonts loaded asynchronously, wait for a page-specific “ready” element or for the relevant image elements to report complete in JavaScript. A fixed sleep can work as a last resort, but it makes runs slower when the page is already ready and unreliable when it is not.
Configure paper, orientation, margins, and backgrounds
Selenium’s PrintOptions exposes common print controls, including orientation, page dimensions, margins, backgrounds, and selected pages or page ranges. Exact property names can vary by language binding and Selenium release, so check the API reference that matches your installed binding.
from selenium.webdriver.common.print_page_options import PrintOptions
print_options = PrintOptions()
print_options.orientation = "landscape"
print_options.background = True
print_options.margin_top = 0.4
print_options.margin_bottom = 0.4
print_options.margin_left = 0.4
print_options.margin_right = 0.4
# A page range can be supplied when supported by your binding:
# print_options.page_ranges = ["1-3"]
pdf_base64 = driver.print_page(print_options)
Use the orientation value supported by your binding—typically portrait or landscape. Dimensions and margins are generally expressed in inches in Selenium’s print options. If your output ignores a setting, verify the installed Selenium version and the binding’s property names rather than assuming the browser supports every option identically.
Make CSS control the paper size
For predictable layouts, add print-specific CSS to the page:
<style>
@media print {
@page { size: A4; margin: 12mm; }
.page-break { break-before: page; }
nav, .screen-only { display: none !important; }
}
</style>
Whether the browser honors CSS page-size preferences can depend on the print implementation and options. Test the generated document with the same browser version used in production.
Print only after dynamic content has settled
Selenium prints the state currently rendered in the browser. It will not magically include content that has not loaded, content hidden behind an interaction, or a virtualized list that has never been rendered.
Rank #2
- CARTRIDGE-FREE PRINTING — Print lab-quality photos, graphics and creative projects; Get vibrant colors and sharp text with Epson's high-accuracy printhead and Claria ET Premium 6-color inks
- INK BOTTLES — Save on photos1 and creative projects with affordable in-house printing; All-in-one printer allows you to print 4" x 6" photos for about 4 cents each vs. 40 cents with traditional ink cartridges1
- LESS FREQUENT INK REPLACEMENT — Replacement ink bottles don't have to be changed nearly as often as ink cartridges¹; Printer, scanner and copier lets you print up to 6,200 color pages³
- PRINT FOR LONGER — Up to 2 years of ink in the box² (and with every replacement ink set) for fewer out-of-ink frustrations with this wireless printer
- ZERO CARTRIDGE WASTE — Epson EcoTank printer helps reduce the amount of cartridge waste ending up in landfills; Cartridge-free printer uses high-yield ink bottles; Each replacement ink bottle set is equivalent to about 100 individual ink cartridges⁴
- Wait for a report container, chart canvas, or “loaded” marker.
- Scroll or trigger the application’s “load more” behavior before printing when content is lazy-rendered.
- Expand accordions and tabs if their contents must appear.
- Set a sufficiently large window size when responsive breakpoints change the document layout.
- Use print CSS to hide navigation, cookie notices, and controls that should not appear on paper.
Authentication must be completed before the print call. You can log in through Selenium, restore a session cookie, or navigate to a page that is already accessible to the browser context. Do not put credentials in a URL.
Printing versus downloading an existing PDF
Print the rendered HTML page
This workflow navigates to HTML and calls print_page(). The browser lays out the current page and returns newly generated PDF data.
Free tools Windows power users keep installed
One-click scans. No signup required.
Download a PDF served by a URL
If a link responds with application/pdf, it is an existing file download, not a page-print operation. Use an HTTP client or a browser download workflow appropriate to your authentication and deployment environment. The Selenium print documentation does not establish one universal download recipe for authenticated files and all browsers, so keep download handling separate from PDF printing.
Chromium-specific control with the DevTools Protocol
When you need options beyond Selenium’s common print settings, Chromium’s DevTools Protocol provides Page.printToPDF. Its documented parameters include landscape mode, print backgrounds, page ranges, header and footer templates, explicit paper dimensions and margins, CSS page-size preference, streaming output, and tagged-PDF generation. See the Page domain reference.
result = driver.execute_cdp_cmd("Page.printToPDF", {
"printBackground": True,
"landscape": False,
"preferCSSPageSize": True,
"displayHeaderFooter": False
})
with open("page.pdf", "wb") as output:
output.write(b64decode(result["data"]))
This is Chromium-specific, and some protocol parameters are experimental. Use it when you control Chromium and need those additional controls; use Selenium’s print API when WebDriver portability is more important.
| Approach | Best for | Portability | Notable controls |
|---|---|---|---|
Selenium print_page() |
Standard WebDriver automation | WebDriver-oriented; output can differ by browser | Orientation, dimensions, margins, backgrounds, page ranges |
Chromium Page.printToPDF |
Chromium-only pipelines needing fine control | Chromium-specific | Headers/footers, CSS page size, streaming, tagged PDF, ranges |
Selenium’s browser documentation notes that Chromium printing requires headless mode in its example. Verify the requirement against your targeted browser and current Selenium release. Selenium supports multiple browsers, but capabilities and output are not identical; its Supported Browsers page and the Firefox Python API describe browser-specific behavior. Firefox’s API describes a best-effort PDF based on supplied parameters, so validate pagination and fonts on the browser you deploy.
Rank #3
- SET IT UP ONCE AND PRINT WITH CONFIDENCE. No complicated maintenance. Just easy, reliable printing you can count on.
- INK FOR YEARS. NOT MONTHS. Up to 2 years of ink included. Get thousands of pages of cartridge-free printing. More pages, less hassle
- KEEPS PRINTING WELL AFTER COMPETITORS HAVE QUIT. No complex maintenance. Sharper text, richer colors.[2] Only with HP Smart Tank
- PREMIUM SUPPORT - Strong technical expertise to solve issues faster
- THE LAST PRINTER YOU'LL EVER NEED. Enjoy years of refillable, cartridge-free printing.
Complete reusable function
from base64 import b64decode
from pathlib import Path
from selenium import webdriver
from selenium.webdriver.common.print_page_options import PrintOptions
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
def html_to_pdf(url: str, output_path: str) -> None:
options = webdriver.ChromeOptions()
options.add_argument("--headless")
driver = webdriver.Chrome(options=options)
try:
driver.get(url)
WebDriverWait(driver, 30).until(
EC.presence_of_element_located((By.CSS_SELECTOR, "body"))
)
print_options = PrintOptions()
print_options.background = True
data = driver.print_page(print_options)
Path(output_path).write_bytes(b64decode(data))
finally:
driver.quit()
html_to_pdf("https://example.com", "page.pdf")
The body wait only confirms that a document exists. Replace it with a selector that represents the finished application state for real reports.
Troubleshooting common failures
“Print” is unavailable or returns an error
With Chromium, add headless mode and confirm that the browser and driver versions are compatible. In containers, also verify that the browser can start with the available sandbox and shared-memory settings.
The PDF is blank or missing sections
The print call captured the page before JavaScript finished, or the content is virtualized or hidden. Wait for a meaningful selector, trigger expansion or scrolling, and inspect the DOM immediately before printing.
Images or fonts are absent
Wait for those resources, check that the browser can reach their URLs, and avoid printing immediately after navigation. Cross-origin restrictions, blocked requests, or application code that only loads assets after scrolling can affect the result.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Layout is clipped or unexpectedly paginated
Check responsive breakpoints, viewport size, @page rules, element overflow, and margins. Try landscape orientation or a larger paper size, then compare the result on the same browser version used in CI.
The file cannot be opened
Ensure Base64 is decoded and the file is opened with "wb". A valid PDF normally begins with the bytes represented by %PDF; logging the first decoded bytes can distinguish a decoding mistake from a rendering failure.
Rank #4
- Wireless Bluetooth Printer: Portable thermal printer compatible with iPhone, Android phones, iPad and tablet computers via Bluetooth. For smartphones, please download the "Nada Print" App. You can also connect to laptops and computers for printing using a USB-C cable. (Note: Laptops and computers can only be connected via USB and require the installation of a driver first. Bluetooth connection is not supported.)
- No-ink printing: Only supports US Letter and A4 size thermal paper.(Doesn't support regular paper) The no-ink portable thermal printer uses direct thermal technology, requiring no ink, toner or ribbons, making it environmentally friendly, cost-effective and time-saving. The thermal printer package comes with a roll of US Letter thermal printing paper. Note: When installing the paper, remember to switch the paper size switch on APP
- Clear Print: NDYIN N80 portable thermal printer adopts high-definition printing technology, with a 203DPI resolution to provide you with clear printing results. This mobile printer is compatible with roll paper, folded paper and tattoo transfer paper, supporting printing from your mobile phone PDF, Word, pictures and web pages anytime and anywhere. It is recommended to use our NDYIN thermal paper to achieve good printing quality
- Portable wireless printer for travel: The thermal printer is equipped with a built-in 1500mAh rechargeable battery, which can print 160 sheets of 8.5" x 11" thermal paper after being fully charged. It weighs only 1.5 pounds and is compact in size. This ink-free portable printer can be easily carried in a backpack or briefcase! It is perfect for business travel, cars, small offices, construction sites, schools and homes. You can print documents, contracts, invoices and boarding passes anytime and anywhere
- The N80 thermal printer has a wide range of uses. The package includes the N80 printer, a roll of US Letter paper(7m/roll), a user manual, a guide card, a type-C soft cable and a type C adapter. Note: The charging adapter is not included. Special thermal paper is required for use; ordinary paper cannot be used. This ink-free portable thermal printer is suitable for various scenarios such as home, school, travel, office, and outdoor, meeting the printing needs of different groups of people. This tattoo template printer is also compatible with tattoo transfer paper, making it an ideal choice for tattoo art
Output differs between browsers
Printing is implemented by each browser and driver. Pin versions in CI, test representative pages, and avoid promising pixel-identical output across Chrome, Edge, and Firefox.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Performance, reliability, and security notes
- Reuse a browser session for multiple pages when isolation requirements permit; starting a browser for every document adds startup overhead.
- Use explicit timeouts for navigation and readiness waits, and always call
quit()in afinallyblock. - Write to a temporary file and rename it after successful decoding when downstream systems watch an output directory.
- Limit concurrent browsers according to available CPU and memory; PDF rendering can be resource-intensive for long pages and large images.
- Record the URL, browser version, Selenium version, print options, and failure stage so a malformed document can be reproduced.
- Protect session cookies and generated reports. Do not expose authenticated PDF URLs or credentials in logs.
Or skip the browser setup
ScreenshotNeo is a hosted screenshot and PDF API. A single request captures a URL without you managing Selenium, a browser binary, or a driver. It accepts cookie and consent banners like a visitor, then removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each cleanup step can be disabled. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and whether the request was billed.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problemsFor a PDF, use the API’s PDF options documented at ScreenshotNeo documentation. The basic call is:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
Set the request’s output options for PDF when using the API. ScreenshotNeo also offers full-page capture with lazy images loaded, CSS-selector element capture, dark mode, device presets and custom viewports, retina scale, paper size, margins, landscape mode and page ranges, custom CSS and JavaScript, click and wait actions, request blocking, headers, cookies, user agents, authorization, timezone and geolocation, transparent backgrounds, resizing, TTL caching, signed image links, asynchronous jobs with signed webhooks, bulk capture for up to 100 URLs per call, usage data, and an OpenAPI specification. Its MCP server supplies take_screenshot, get_page_info, and capture_pdf tools to Claude, Cursor, and other MCP clients.
Plans include 1,000 screenshots per month free with no card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account to try it.
When to choose each method
- Choose Selenium when your test already owns the browser session, the page requires multi-step interaction, or you need browser-level assertions before creating the document.
- Choose Chromium CDP when the pipeline is intentionally Chromium-only and needs header/footer templates, streaming, tagged PDFs, or other protocol-level controls.
- Choose ScreenshotNeo when you want an API or AI-agent workflow, do not want to maintain browser infrastructure, or need consent and popup cleanup with billing that excludes failed captures.
Frequently Asked Questions
Does Selenium download a PDF from a webpage?
No. Selenium’s print API renders the current HTML page into new PDF data. Downloading an already hosted PDF is a separate file-download or HTTP request workflow.
Why must Chrome run headless for printing?
Selenium’s Chromium browser example states that printing requires headless mode. Confirm this requirement for the browser and Selenium release you deploy.
Can Selenium add headers and footers?
The standard print options cover common layout controls. Chromium’s DevTools Page.printToPDF adds header and footer templates, but it is Chromium-specific.
Which browsers support Selenium PDF printing?
Selenium exposes print APIs across bindings and browsers, but capabilities and output differ. Validate the exact browser, driver, and Selenium versions used in production.
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.

