Free tools Windows power users keep installed
One-click scans. No signup required.
Use Selenium 4’s print_page() API in a headless Chrome or Chromium session. Navigate to the page, wait for its dynamic content and fonts, create PrintOptions, call driver.print_page(), base64-decode the returned data, and write the bytes to a .pdf file. When you need Chrome-only controls such as HTML header and footer templates, call the Chrome DevTools Protocol command Page.printToPDF through Selenium’s execute_cdp_cmd().
The shortest working solution
The following Python script uses Selenium’s normal cross-browser printing interface. Chromium printing must run in headless mode in Selenium’s documented workflow.
import base64
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.print_page_options import PrintOptions
options = Options()
options.add_argument("--headless=new")
driver = webdriver.Chrome(options=options)
try:
driver.get("https://example.com")
print_options = PrintOptions()
print_options.orientation = "portrait"
print_options.page_ranges = ["1-3"]
pdf_base64 = driver.print_page(print_options)
with open("page.pdf", "wb") as output:
output.write(base64.b64decode(pdf_base64))
finally:
driver.quit()
print_page() returns PDF data as a base64-encoded string in the Python binding. The browser does the rendering; Selenium transports the result, so the output reflects Chrome’s print layout rather than a screenshot stitched together by Python.
Prerequisites and browser setup
- Install Selenium 4 for your language and a Chrome or Chromium installation.
- Use a ChromeDriver whose major version matches the installed Chrome or Chromium major version. Selenium documents Selenium 4 compatibility with Chrome 75 and newer, subject to this matching rule.
- Run the browser headlessly when printing. The
--headless=newflag is the current Chrome headless mode. - Make sure the process can write to the destination directory and that outbound requests, authentication and certificates needed by the target page are available to Chrome.
Recent Selenium releases can manage a compatible driver automatically. In controlled build or production environments, pinning Chrome and ChromeDriver versions together makes failures reproducible.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minute#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
Wait for the page before printing
A navigation completing does not guarantee that a single-page application, web font or lazy image has finished rendering. Add an explicit readiness check when the PDF must be deterministic.
from selenium.webdriver.support.ui import WebDriverWait
# Wait for the app's own readiness marker when one exists.
WebDriverWait(driver, 30).until(
lambda d: d.find_element("css selector", "body[data-ready='true']")
)
# Wait for fonts and images that are already in the DOM.
WebDriverWait(driver, 30).until(
lambda d: d.execute_script("""
return document.fonts ? document.fonts.status === 'loaded' : true;
""")
)
WebDriverWait(driver, 30).until(
lambda d: d.execute_script("""
return Array.from(document.images).every(img => img.complete);
""")
)
Replace the readiness selector with a signal supplied by your application. For pages that load content only after scrolling, scroll the relevant container or use the site’s own “all content loaded” state before invoking the print command. Waiting for img.complete only checks that loading finished; it does not prove every image loaded successfully, so inspect img.naturalWidth if broken images matter.
Controlling page size, orientation and ranges with PrintOptions
Use PrintOptions for the normal Selenium workflow. The exact property names below are provided by Selenium’s print examples and bindings; check the version of your language binding when upgrading.
| Requirement | Setting | Practical effect |
|---|---|---|
| Portrait or landscape | orientation = "portrait" or "landscape" |
Changes the orientation used for every selected page. |
| Print selected pages | page_ranges = ["1-3"] |
Prints only pages one through three. Use the range syntax accepted by your Selenium binding. |
| Custom paper dimensions | Page-width and page-height options | Sets the paper dimensions instead of relying on the browser default. |
| Margins | Margin options for top, bottom, left and right | Reserves space around the printable area; large margins can create additional pages. |
| CSS page size | Prefer-CSS-page-size option where available | Lets an author’s @page rule take precedence over a paper-size setting. |
A complete script can set the additional values exposed by your binding, for example:
print_options = PrintOptions()
print_options.orientation = "landscape"
print_options.page_ranges = ["2", "4-6"]
print_options.page_width = 11.69
print_options.page_height = 8.27
print_options.margin_top = 0.4
print_options.margin_bottom = 0.4
print_options.margin_left = 0.4
print_options.margin_right = 0.4
print_options.prefer_css_page_size = True
pdf_base64 = driver.print_page(print_options)
Dimensions and margins are interpreted according to the binding and Chrome’s print implementation. Validate the resulting page count and line breaks after changing them; a small width change can move headings or tables onto a new page.
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⁴
Use print CSS to control the document
Web pages often need a print-specific stylesheet. Hide navigation, expand content that is collapsed on screen, and define paper behavior with @media print and @page.
<style>
@media print {
.site-nav, .cookie-banner, .chat-widget { display: none !important; }
.report-section { break-inside: avoid; }
a { color: #000; text-decoration: none; }
}
@page {
size: A4 portrait;
margin: 14mm 12mm;
}
</style>
If the page is yours, inject a temporary stylesheet before printing or serve a print stylesheet normally. If it is not yours, Selenium can execute JavaScript to hide known selectors, but that changes the document only in the browser session and may not affect cross-origin iframes.
When you need Chrome-specific controls: Page.printToPDF
Selenium’s Chrome WebDriver exposes Chrome DevTools Protocol commands through execute_cdp_cmd(). This is a Chrome-specific fallback, not the portable Selenium printing interface. It is useful for explicit paper dimensions, background graphics, CSS page-size preference and other CDP flags.
Recommended Free Tools
import base64
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("--headless=new")
driver = webdriver.Chrome(options=options)
try:
driver.get("https://example.com")
result = driver.execute_cdp_cmd("Page.printToPDF", {
"printBackground": True,
"displayHeaderFooter": False,
"preferCSSPageSize": True,
"paperWidth": 8.27,
"paperHeight": 11.69,
"marginTop": 0.4,
"marginBottom": 0.4,
"marginLeft": 0.4,
"marginRight": 0.4
})
with open("page.pdf", "wb") as output:
output.write(base64.b64decode(result["data"]))
finally:
driver.quit()
CDP paper dimensions and margins use inches. The command returns a dictionary whose data member contains base64 PDF data. Keep the decode step; writing the encoded text directly produces a file that PDF readers cannot open.
Headers, footers and page ranges with CDP
Set displayHeaderFooter to true and provide headerTemplate and footerTemplate when you need Chrome’s generated page number, title or URL fields. CDP also accepts a pageRanges string and a landscape flag. Templates are small HTML fragments; keep their CSS inline and account for the header and footer space in the margins.
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.
result = driver.execute_cdp_cmd("Page.printToPDF", {
"landscape": False,
"printBackground": True,
"displayHeaderFooter": True,
"headerTemplate": "<div style='font-size:8px;width:100%;text-align:center'>Quarterly report</div>",
"footerTemplate": "<div style='font-size:8px;width:100%;text-align:center'>Page <span class='pageNumber'></span> of <span class='totalPages'></span></div>",
"pageRanges": "1-5",
"marginTop": 0.6,
"marginBottom": 0.6
})
Chrome’s CDP schema changes over time. If a flag is rejected, compare the command’s parameters with the CDP version shipped by your Chrome rather than assuming the Selenium API is portable to another browser.
Java and Selenium DevTools
Java offers the same two choices: use the high-level PrintsPage/PrintOptions API for a portable Selenium workflow, or obtain a DevTools session and send the versioned Page.printToPDF command for Chrome-specific control. The Java DevTools binding exposes options for landscape orientation, header and footer display, background graphics, scale, paper width and height, all four margins, page ranges, header and footer templates, CSS page-size preference, transfer mode, tagged PDFs and document outlines.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minuteBecause the generated Java CDP classes are tied to the Chromium protocol version, import the Page class matching the DevTools version bundled with your Selenium release. Treat the method signature as versioned: upgrade Selenium and Chrome together, then update the generated command arguments if your IDE reports a signature change. The high-level Java print API is the safer default when you do not need those Chrome-only fields.
Troubleshooting common failures
| Symptom | Likely cause | Fix |
|---|---|---|
SessionNotCreatedException or Chrome exits immediately |
Chrome and ChromeDriver major versions do not match, or the binary is unavailable. | Install matching major versions, set the correct Chrome binary location when necessary, and run the same command under the service account used in production. |
DevToolsActivePort file doesn't exist |
Chrome could not start in the environment, often because of an unsuitable sandbox or profile directory. | Use a writable temporary user-data directory, avoid reusing a locked profile, and verify that headless Chrome can start outside Selenium. |
| The PDF is blank or only contains the shell | The app renders asynchronously or requires authentication and JavaScript. | Wait for an application readiness marker, confirm the URL and login state in the same driver, and inspect driver.page_source before printing. |
| Images or colors are missing | Resources were not loaded, or background printing is disabled. | Wait for images and fonts, check network and certificate errors, and set printBackground to true with CDP when backgrounds are required. |
| Only some pages appear | A page range was supplied or content reflow changed the page count. | Remove page_ranges/pageRanges while diagnosing, then calculate ranges from the final rendered document. |
| PDF readers report a corrupt file | The base64 string was written as text or truncated. | Decode the returned value with base64.b64decode and write binary bytes; check disk space and file size. |
| Fonts differ from a visible desktop browser | The headless host lacks the font or the web font was not ready. | Install the required fonts in the runtime image and wait for document.fonts.status to become loaded. |
Performance, reliability and operational safeguards
- Reuse a driver for a batch. Starting Chrome dominates small jobs. Navigate sequentially in one isolated session, clear cookies between tenants, and quit the driver in a
finallyblock. - Set bounded waits. Use explicit timeouts for navigation and readiness checks so one broken page cannot hold a worker forever. Capture logs and the URL when a timeout occurs.
- Control resource growth. Very long pages, large images and many simultaneous Chrome processes consume substantial memory. Limit concurrency and write PDFs incrementally to durable storage.
- Make output reproducible. Pin Chrome, ChromeDriver and Selenium versions, install fonts in the image, set the timezone where date rendering matters, and record the print options with each artifact.
- Protect the browser. Do not pass untrusted URLs into a privileged network environment without SSRF controls. Use a restricted account, isolated profile and appropriate egress policy; pages can execute JavaScript during rendering.
- Understand cost. Selenium, Chrome and ChromeDriver do not charge per PDF. Your costs are the machine time, storage and network resources needed to run them.
Or skip the browser setup
ScreenshotNeo provides a hosted PDF and screenshot endpoint when maintaining Chrome workers is not worthwhile. It accepts the cookie or consent banner like a visitor and 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 the response identifies the result with X-Page-Verdict and X-Billed headers. Its MCP server supplies take_screenshot, get_page_info and capture_pdf tools to Claude, Cursor and other MCP clients.
The API call is a single GET request (see the ScreenshotNeo API documentation):
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
For 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)
For 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 also supports PDF paper size, margins, landscape mode and page ranges, plus full-page lazy-image loading, selectors, custom CSS and JavaScript, waits, blocking rules, headers, cookies, user agents, authorization, timezone, geolocation, caching, signed links, asynchronous jobs, 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.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →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
Choosing between the two approaches
Use Selenium when the PDF is part of an existing browser test or application, when you need to execute authenticated workflows step by step, or when you need complete control over a local Chrome runtime. Use ScreenshotNeo when you want an HTTP call, managed cleanup of consent UI and failed-page billing protection, or an MCP workflow for AI agents. Both approaches still require you to verify the final PDF for page breaks, fonts and legally required content.
Frequently Asked Questions
Can I generate a PDF without opening a visible Chrome window?
Yes. Add Chrome’s --headless=new argument and run the Selenium print call in the headless session.
What does Page.printToPDF add over print_page()?
It exposes Chrome-specific fields such as header and footer templates, background printing, explicit paper dimensions, page ranges and CSS page-size preference.
Why does my PDF contain a page that was not visible in the browser tab?
Printing uses the document’s print layout, which can differ from the viewport. Check @media print, @page, expanded sections and the selected paper dimensions.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Are Selenium PDFs billed by Selenium itself?
No. Selenium, Chrome and ChromeDriver are software; operating costs come from the machines, storage and network resources that run your jobs.
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.

