Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
Use Selenium’s page-printing API to create a PDF from each browser session, then package the browser-specific PDFs or merge them in a separate PDF-processing step. In Java, configure PrintOptions, call the print interface exposed by your chosen Selenium and browser combination, decode the returned PDF content, and save it. Chrome and Firefox examples are available; do not assume their output will look identical or that Selenium merges the files for you.
What “one report across multiple browsers” means
A Selenium print call produces PDF content for the page open in one WebDriver session. If you run the same workflow in Chrome and Firefox, you will normally have one PDF from each browser. That is useful when you need to compare rendering or retain browser-specific evidence.
If the deliverable must be literally one PDF file, merging those outputs is a separate operation. The Selenium print examples do not perform that merge. Decide which output you need before building the job:
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →- Browser report package: retain separate PDFs, named with browser and version, alongside a manifest or summary.
- Single merged PDF: print from each browser, then combine the resulting files with a PDF library or other approved PDF-processing step.
PDFs from different rendering engines may differ in pagination, font substitution, image loading, and print CSS. Treat the files as browser-specific results, not guaranteed identical copies.
#1 Best Overall
Prerequisites and browser coverage
Use a Selenium Java version compatible with your Java runtime and the browser drivers in your environment. Selenium’s official print-page documentation describes Java printing through PrintsPage and BiDi’s BrowsingContext. The supported-browsers page lists browser-specific Selenium capabilities, but support for a browser does not guarantee identical print features across browsers: Selenium supported browsers.
A practical Java example covers Chrome and Firefox. Its pinned Selenium Java 4.23.1 and WebDriverManager 5.8.0 versions are examples from that tutorial, not a statement that they are current: Baeldung’s Selenium PDF tutorial. Select versions deliberately for your project.
For Chrome, keep Chrome and ChromeDriver aligned. ChromeDriver’s documentation gives compatibility and release guidance, including the Chrome for Testing release process for versions beginning with M115: ChromeDriver documentation. In CI, pin and update the browser and driver together rather than relying on whichever binaries happen to be installed.
Print a page to PDF in Java
The following core pattern uses the Selenium printing interface documented for Java. It assumes a live driver has already navigated to the report page and that the application is ready to print. Pdf.getContent() returns content encoded for transfer; decode it before writing the PDF bytes.
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Base64;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.print.Pdf;
import org.openqa.selenium.print.PrintOptions;
import org.openqa.selenium.print.PrintsPage;
public final class BrowserPdf {
private BrowserPdf() {}
public static void save(WebDriver driver, Path outputPath) throws Exception {
PrintOptions options = new PrintOptions();
options.setOrientation(PrintOptions.Orientation.PORTRAIT);
Pdf pdf = ((PrintsPage) driver).print(options);
byte[] bytes = Base64.getDecoder().decode(pdf.getContent());
Files.write(outputPath, bytes);
}
}
Check that the specific driver implements PrintsPage in the Selenium version you deploy. The official documentation also describes a BiDi route; availability depends on the API and browser support in your deployment.
Rank #2
Configure page layout
PrintOptions supports layout controls such as orientation, page size, scaling, and margins. The Selenium documentation and Java tutorial show the relevant options. Set only the choices your report needs, and validate the resulting pages; CSS and browser rendering can affect how settings appear in the final document.
PrintOptions options = new PrintOptions();
options.setOrientation(PrintOptions.Orientation.LANDSCAPE);
options.setPageSize(PrintOptions.PageSize.A4);
options.setScale(0.9);
options.setPageRanges("1-5");
Use page ranges only when you intend to omit pages. Before relying on the exact methods or accepted values, check the API for your Selenium release. Background printing and other print controls are also documented, but the precise configuration should be tested with the report and selected browser.
Recommended Free Tools
Run the same report in Chrome and Firefox
For a cross-browser run, put browser creation behind a small factory, then call the same navigation, readiness, and save logic for each driver. The following illustrates the orchestration; configure driver installation and versions according to your project. Always quit each driver even when navigation or printing fails.
import java.nio.file.Path;
import java.time.Duration;
import java.util.List;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.By;
public class CrossBrowserReport {
record BrowserRun(String name, WebDriver driver) {}
public static void main(String[] args) throws Exception {
String reportUrl = "https://example.com/report";
List<BrowserRun> runs = List.of(
new BrowserRun("chrome", new ChromeDriver()),
new BrowserRun("firefox", new FirefoxDriver())
);
for (BrowserRun run : runs) {
try {
WebDriver driver = run.driver();
driver.get(reportUrl);
new WebDriverWait(driver, Duration.ofSeconds(30))
.until(d -> d.findElement(By.cssSelector("main.report")).isDisplayed());
// Replace this readiness condition with one that reflects
// the report's actual data, images, and print layout.
BrowserPdf.save(driver, Path.of("report-" + run.name() + ".pdf"));
} finally {
run.driver().quit();
}
}
}
}
Replace the example URL and selector with your report’s values. A visible container alone may not mean charts, asynchronous data, web fonts, or images have finished loading. If those assets matter, wait for an application-specific ready marker and confirm the print stylesheet is active before invoking print.
For production code, create each driver inside the loop or in a factory that can clean up if the second browser fails to start. The compact example constructs both drivers before entering the loop; if construction itself throws, an already-created driver may need explicit cleanup.
Rank #3
Use WebDriver BiDi when appropriate
Selenium’s official print documentation also demonstrates a BiDi approach using a BrowsingContext and PrintOptions. Enable WebDriver BiDi by setting the webSocketUrl capability, obtain the current window’s browsing context, then call its print method. Selenium’s Java example currently shows this route with ChromeDriver. Verify the exact API and browser support for your Selenium version before choosing it; do not assume the BiDi print path is interchangeable across every browser and driver.
For a simple Java project, the PrintsPage flow is straightforward where supported. Prefer BiDi if your implementation requires that interface and the selected browser stack supports it. In either case, the print call is per browser session.
Make the outputs useful as a report
Name files and preserve run metadata
Include browser and version in output filenames or a manifest, for example report-chrome-<version>.pdf and report-firefox-<version>.pdf. Record the tested URL, run time, Selenium version, browser version, and whether the job completed. This makes a later rendering discrepancy easier to reproduce.
Validate print-specific details
Inspect representative PDFs from every browser configuration. Check page count, required text, page breaks, margins, headers and footers, and whether fonts, images, charts, and backgrounds appear as intended. Adjust the site’s print CSS or the print options when the layout is wrong, then rerun the same checks.
Merge only if the deliverable requires it
If consumers need one file, add an explicit PDF-merging stage after the browser captures. Choose and document a PDF library suitable for your project, preserve the intended browser ordering, and validate the merged result. Merging does not reconcile differences in how Chrome and Firefox laid out the source page; it simply places the generated pages into one document.
Free tools Windows power users keep installed
One-click scans. No signup required.
Rank #4
Performance, reliability, and cost considerations
- Wait for meaningful readiness: printing too early can capture loading states or missing assets. Wait on report-specific signals instead of adding an arbitrary delay as the only synchronization method.
- Control resource use: each browser session consumes resources. Run sessions sequentially for simpler cleanup and lower concurrent load, or parallelize only when your CI capacity and driver management support it.
- Keep versions reproducible: browser and driver updates can change rendering or compatibility. Pin a known working combination, then test updates as a deliberate change.
- Use cleanup paths: call
quit()infinallyso failures do not leave browser or driver processes behind. - Budget for the actual deliverable: a multi-browser job performs a print operation per browser, plus any later merge and validation. The sources do not establish a general runtime or cost figure; measure in your own CI environment.
Troubleshooting common failures
Class cast failure or missing print method
Cause: the selected driver or Selenium version may not expose the expected printing interface. Fix: check the driver implementation and the Java print API for your exact Selenium version; use a supported BiDi route only where enabled and supported.
PDF content is invalid or cannot be opened
Cause: the returned content was written without decoding, or the response content was otherwise mishandled. Fix: decode pdf.getContent() with Java’s Base64 decoder, write the resulting bytes, and verify that the file is non-empty and opens in a PDF reader.
Blank or incomplete pages
Cause: the page was printed before data or assets were ready, or the print layout differs from the screen layout. Fix: wait for a report-specific ready condition; check print CSS, fonts, image loading, and browser-specific behavior.
Chrome session fails after a browser update
Cause: Chrome and ChromeDriver versions may be incompatible. Fix: align their major versions and consult the official ChromeDriver release and compatibility guidance for the version deployed.
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 minuteTwo PDFs differ in page count or layout
Cause: different browser engines can render print content differently. Fix: compare the CSS, fonts, page dimensions, margins, and asset readiness in each browser, then adjust the report or accept separate browser-specific results. Do not treat a merged file as proof of rendering parity.
Best Value
Or skip the browser setup
If your goal is to capture a website as an image or PDF rather than exercise Selenium’s cross-browser rendering, ScreenshotNeo offers a one-request screenshot API and an MCP server for AI agents. Its screenshot endpoint returns PNG, JPEG, WebP, or PDF; it is a different workflow from generating per-browser Selenium output.
Use a key from your account and replace the URL as needed. See the ScreenshotNeo API documentation for request options.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
ScreenshotNeo accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; these steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and each response indicates the page verdict and billing status in headers. Its MCP server exposes take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Sign up for 1,000 free screenshots a month, with no card required.
Frequently Asked Questions
Does Selenium merge Chrome and Firefox PDFs automatically?
No. Selenium’s print call produces PDF content for a browser session; combining files is a separate PDF-processing step.
Will Chrome and Firefox produce visually identical PDFs?
Not necessarily. Browser engines can differ in print CSS, fonts, pagination, and asset rendering, so inspect outputs from each target browser.
Can the same Java print options be used with Safari or Edge?
Do not assume so. Confirm the print interface and option support for the Selenium version and specific browser driver you deploy.
Outdated 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 matchPC 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 & 11Quick 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.

