Recommended Free Tools
If Selenium has already logged in, the simplest way to save the protected page as a PDF is to print it from that same Selenium-controlled browser. This avoids transferring authentication to a separate browser. Use Qt WebEngine’s printToPdf instead when the authenticated page is displayed inside your PyQt5 interface; log in in that WebEngine profile and wait for its asynchronous PDF completion signal.
Choose which browser should render the PDF
There are two practical paths, and the deciding question is where the authenticated page already lives:
- Keep Selenium as the renderer when it has already logged in and can navigate to the content. Selenium’s print command returns PDF data for the current page; save that data without creating another browser session. The Selenium guide documents print settings including orientation, scale, background graphics, and shrink-to-fit: Selenium Print Page.
- Use Qt WebEngine as the renderer when the page is shown or controlled within a
QWebEngineView. Authenticate in that WebEngine profile, then callQWebEnginePage.printToPdfand wait for completion. The Qt 5.15 API describes this operation as asynchronous: QWebEnginePage Class, Qt WebEngine 5.15.1.
Do not assume that a Selenium login automatically logs in a new QWebEngineView. Qt documents a cookie store associated with a WebEngine profile and synchronization with QNetworkAccessManager, not automatic sharing with Selenium: Qt WebEngine Overview. If the page belongs in the desktop UI, authenticating within its WebEngine profile is usually the more direct design.
Print a page from the existing Selenium login
The following example uses Selenium’s current page-print API, waits for an application-specific readiness condition, and writes the returned base64 PDF data to disk. The exact print options and browser support depend on the Selenium, browser, and driver versions installed in your application; check the Selenium guide for the API supported by your deployed combination.
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 →#1 Best Overall
import base64
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
def save_authenticated_page_as_pdf(driver, url, output_path):
driver.get(url)
# Replace this selector with a reliable element that appears only when
# the intended authenticated content is ready.
WebDriverWait(driver, 30).until(
EC.presence_of_element_located((By.CSS_SELECTOR, "main"))
)
# Optional but useful: detect a login redirect or access-denied state
# with a site-specific check before printing.
if "/login" in driver.current_url.lower():
raise RuntimeError("The browser is not on the authenticated page")
result = driver.print_page()
pdf_bytes = base64.b64decode(result)
Path(output_path).write_bytes(pdf_bytes)
if __name__ == "__main__":
driver = webdriver.Chrome()
try:
# Perform the site's login in this same driver before calling this.
save_authenticated_page_as_pdf(
driver,
"https://example.com/account/report",
"report.pdf",
)
finally:
driver.quit()
The example deliberately does not automate a site’s login form: the authentication flow, multi-factor prompts, and permitted automation vary by site. Log in using your existing Selenium workflow, then call save_authenticated_page_as_pdf with the protected URL. Replace the sample URL, readiness selector, and login-redirect test with checks that match the application. A generic element such as main is only a starting point; a site-specific report heading or loaded-state marker is stronger evidence that the right content is ready.
Print configuration and page readiness
Selenium’s print API accepts print options for page layout. The official guide illustrates orientation, scale, background inclusion, and shrink-to-fit. Use the options supported by the Selenium version in your application; do not assume a setting is honored identically across every browser and driver combination. For example, a print call can be configured along these lines:
from selenium.webdriver.common.print_page_options import PrintOptions
options = PrintOptions()
options.orientation = "landscape"
options.scale = 1
options.background = True
options.shrink_to_fit = True
pdf_base64 = driver.print_page(options)
Use portrait unless the content is genuinely wider than it is tall. Background graphics can matter for colored charts or designed reports, but may increase output size. Shrink-to-fit can help wide content fit, at the cost of smaller text. Confirm the generated PDF with representative pages instead of treating a successful API response as proof that its layout is readable.
Wait for a meaningful condition instead of sleeping for an arbitrary number of seconds. A page can become interactive before images or client-rendered data finish loading. If the app exposes a report-ready element or a status marker, wait for it. Also verify the URL and a piece of intended content before printing, so a login redirect, access-denied page, or empty state does not become a seemingly valid PDF.
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 & 11Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchRank #2
Render the authenticated page in PyQt5 with Qt WebEngine
Choose this route if the view inside the PyQt5 application is the page you want to save. The WebEngine page must already be authenticated and rendered. In Qt 5.15, printing to a file is asynchronous: connect pdfPrintingFinished, call printToPdf, and keep the page and view alive until the signal arrives. The documented default page layout is A4 portrait, and an existing destination file is overwritten.
Here is a minimal PyQt5 pattern. It assumes the application has already created and authenticated a QWebEngineView. Check the exact overload and signal signature against the PyQt5 and Qt WebEngine versions installed in your target environment; the Qt 5.15 reference is a behavioral reference rather than a guarantee for every Python binding build.
from pathlib import Path
from PyQt5.QtCore import QUrl
from PyQt5.QtWebEngineWidgets import QWebEngineView
def save_view_as_pdf(view: QWebEngineView, output_path: str) -> None:
page = view.page()
destination = str(Path(output_path).resolve())
def finished(file_path: str, success: bool) -> None:
if success:
print(f"PDF saved to {file_path}")
else:
print(f"PDF generation failed: {file_path}")
# Update the application's UI here. Keep the view/page alive until
# this callback runs.
page.pdfPrintingFinished.connect(finished)
page.printToPdf(destination)
# Example setup only: the application must arrange authentication and
# wait for the protected content to render before printing.
view = QWebEngineView()
view.load(QUrl("https://example.com/account/report"))
# Call save_view_as_pdf(view, "report.pdf") only after the page is ready.
For an actual desktop app, replace the print calls with a Qt signal, status label, or dialog. Do not call the function immediately after load() and expect the page to be ready: wait for successful load and, when necessary, a site-specific content-ready condition. The browser load-complete event alone may not mean that a single-page app has finished fetching or drawing its data.
Qt version and layout considerations
The cited API page documents the Qt 5.15 behavior. Qt 6.5’s official API also describes asynchronous PDF output, but its API should not be substituted blindly into a Qt 5 application: QWebEnginePage Class, Qt WebEngine 6.5. PyQt5 packages bundle or target particular Qt versions, so check the actual runtime and binding signature before relying on a copied example.
Rank #3
Qt WebEngine offers a page-layout overload for page size and orientation in the Qt 5.15 API. Set layout explicitly if the default A4 portrait output is not suitable, and avoid selecting an existing user file unintentionally because the API overwrites it. The PDF feature is provided by Chromium, according to Qt WebEngine Features.
Move authentication state only when you must
If login takes place in Selenium but the PDF must be rendered by Qt WebEngine, treat the two as separate browser sessions. A cookie is often only one part of a site’s session: the site may also rely on local storage, CSRF state, browser characteristics, or device checks. Copying cookies is not a general-purpose session migration method.
Qt associates cookies with a WebEngine profile and exposes APIs to load, set, observe, and delete them. Cookie-store operations are asynchronous, so do not start navigation or PDF generation until the relevant operation has completed and you have confirmed authenticated access. See the Qt WebEngine overview for the profile and cookie-store context.
- Transfer only the minimum authentication state required, and preserve domain, path, secure, expiry, and SameSite attributes where applicable.
- Keep cookie values out of logs, source code, and broadly readable temporary files; they are credentials.
- Protect any transfer in transit and at rest, and clear temporary credentials when they are no longer needed.
- After setting state in Qt, load the protected page and verify it is authenticated before printing.
These are security and implementation precautions, not a guarantee that a particular site’s login can be reproduced by copying cookies. When feasible, use one authenticated browser context from navigation through printing.
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 →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Rank #4
Compare the two approaches
| Decision | Selenium prints | Qt WebEngine prints |
|---|---|---|
| Where login happens | Uses the Selenium browser session that already logged in. | Requires login in the WebEngine profile or deliberate authentication transfer. |
| Best fit | Save content Selenium already controls, without creating another browser context. | Save content displayed or controlled inside the PyQt interface. |
| PDF operation | Prints the current page and returns encoded PDF data to save. | printToPdf writes asynchronously; observe completion in Qt 5.15. |
| Documented layout controls | Orientation, scale, background graphics, and shrink-to-fit in Selenium’s guide. | Page layout controls including paper size and orientation in the Qt 5.15 API. |
| Main implementation risk | Browser/driver support and verifying the returned print result. | Separate session management and retaining the page until asynchronous completion. |
Troubleshooting
The PDF contains a login page
The browser was not authenticated for the URL being printed, or the session expired. Confirm the current URL and a protected-page element before printing. If switching from Selenium to Qt WebEngine, remember that a fresh WebEngine profile does not automatically inherit Selenium’s session.
The PDF is blank or missing dynamic content
Printing may have started before client-rendered content was ready. Wait for a page-specific element or application-ready state, then inspect the rendered page before calling the print API. A fixed delay can sometimes mask a race, but it is less reliable than waiting for a meaningful condition.
Qt reports failure or no file appears
Check that the destination directory exists and is writable, keep the page alive through the completion signal, and inspect the signal’s success value. Avoid writing to a file that the user expects to preserve: the Qt 5.15 API says an existing output file is overwritten.
The Python call or signal does not match the example
Check the installed PyQt5, Qt WebEngine, Selenium, browser, and driver versions. Python binding overloads and supported browser behavior can differ. Use documentation for the deployed versions rather than copying a Qt 6 signature into a Qt 5 application.
Best Value
The PDF layout is clipped or hard to read
Try portrait versus landscape, review scale and shrink-to-fit, and decide whether background graphics are needed. Wide tables often need landscape or a smaller scale; reducing scale can make body text unreadable, so inspect the output rather than optimizing for a single page at any cost.
A transferred cookie does not authenticate Qt
Check cookie attributes and whether the site needs state beyond cookies. Wait for asynchronous cookie-store operations to finish, then verify access in WebEngine. If the site binds a session to other browser state, copying cookies alone may not work; authenticate in the Qt profile instead.
Or skip the browser setup
If the task is simply to capture a page as a PDF and you do not need your existing Selenium browser context, ScreenshotNeo offers a one-request screenshot API that can also return PDFs. This is a different workflow from printing a Selenium session: it does not reuse the login state held by your Selenium browser.
For endpoint parameters and PDF options, see the ScreenshotNeo documentation. A cURL request for a PDF is:
curl -G "https://api.screenshotneo.com/v1/shot"
-d access_key=YOUR_API_KEY
--data-urlencode url=https://example.com/report
-d format=pdf
-o report.pdf
ScreenshotNeo removes cookie/consent banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, failed loads, and cache hits are not billed. Its MCP server lets AI agents use screenshot tools. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Sign up for ScreenshotNeo’s free plan.
FAQ
Can Selenium save a PDF without opening a second browser?
Yes. Print the current page from the Selenium-controlled browser and save the returned PDF data.
Does Qt WebEngine automatically share cookies with Selenium?
No automatic sharing is documented. Treat them as separate sessions unless your application explicitly shares or transfers authentication state.
Does Qt WebEngine PDF printing finish immediately?
No. The Qt 5.15 API documents the operation as asynchronous and provides a completion signal.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
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.




