We use cookies to analyze site traffic and show personalized ads. You can accept all cookies or decline personalized advertising.
Learn more in our Privacy Policy.
Exporting a dashboard view as a PDF report using Selenium’s PrintsPage interface.
Selenium can use the browser’s built-in print capability to generate a PDF of the current page. Instead of clicking “Print” manually, you configure a PrintOptions object and call print() via the PrintsPage interface.
print(PrintOptions).setOrientation(LANDSCAPE): For wide tables/charts.setScale(0.8): Zooms content to 80%.setBackground(true): Includes background colors/images.setShrinkToFit(true): Ensures content fits the page.setBackground(true) on for dashboards and rich visuals. Turn it off for plain text documents to save ink and keep it clean.Monthly Sales Dashboard
Date: November 26, 2025
| Order ID | Customer | Total | Status |
|---|---|---|---|
| #1001 | Alice Smith | $45.00 | Paid |
| #1002 | Bob Johnson | $82.50 | Shipped |
| #1003 | Carol Williams | $19.99 | Pending |
| Grand Total | $147.49 | ||
This is the dashboard you will print to PDF!
123456789101112131415PrintOptions printOptions = new PrintOptions();
printOptions.setOrientation(PrintOptions.Orientation.LANDSCAPE);
printOptions.setPageSize(new PageSize(27.94, 21.59));
printOptions.setPageMargin(new PageMargin(1.0, 1.0, 1.0, 1.0));
printOptions.setScale(0.8);
printOptions.setShrinkToFit(true);
printOptions.setBackground(true);
PrintsPage printer = (PrintsPage) driver;
Pdf pdf = printer.print(printOptions);
String base64Pdf = pdf.getContent();
byte[] decodedPdf = java.util.Base64.getDecoder().decode(base64Pdf);
driver.quit();Pdf object.Always wait for charts, tables, and async data to finish loading before calling print()—otherwise your PDF may capture half-rendered content.
Include timestamps in the filename (e.g., sales_dashboard_2025-11-26.pdf) to avoid overwrites.
Turn setBackground(true) on for dashboards; consider disabling it for text-only documents to keep PDFs clean.