Version 1.3.1
SwingToPDF converts any Java Swing component tree into genuine vector PDF output. Text remains selectable, graphics stay sharp at any zoom level, and the output is a fraction of the size of rasterized alternatives.
| Guide | Description |
|---|---|
| Getting Started | Installation, dependencies, JVM flags, and your first export |
| Export Modes | DATA_REPORT vs UI_SNAPSHOT -- when to use each and how they differ |
| Builder Options | Complete reference for every SwingPdfExporter builder method |
| Pagination | How content flows across pages, margins, keep-together, and scaling |
| Headers & Footers | Page banners with dynamic page numbers, styling, alignment, and per-page variation |
| AcroForm Fields | Exporting interactive, fillable PDF form fields from Swing components |
| Fonts | Font embedding, the resolution chain, custom FontResolver, and fallbacks |
| Supported Components | Every Swing component with handler-specific rendering details |
| Vector Handlers | Render custom-painted components as vector PDF with registerHandler |
| Troubleshooting | Common issues, error messages, and how to fix them |
SwingPdfExporter.from(myPanel)
.pageSize(PageSize.LETTER)
.orientation(Orientation.LANDSCAPE)
.margins(36, 36, 36, 36)
.title("Quarterly Report")
.header(HeaderFooter.of("Quarterly Report").align(Alignment.LEFT))
.footer(HeaderFooter.of("Page {page} of {pages}"))
.export(Path.of("report.pdf"));- Vector-first rendering -- handlers read Swing component state directly and emit PDF drawing operations. Text is real PDF text (selectable, searchable); shapes are real vector paths.
- Vector component handlers -- register a
VectorComponentHandlerviaregisterHandler()to render custom-painted components (charts, diagrams) as vector PDF instead of rasterised bitmaps. - Raster fallback -- components without a dedicated handler or registered vector handler (or with custom
paintComponentoverrides) are rasterized at high quality and embedded as images. - Two export modes --
DATA_REPORTexports all data (every table row, every tab, full scroll content).UI_SNAPSHOTcaptures exactly what is visible on screen. - Automatic pagination -- content taller than one page is split intelligently at row boundaries and keep-together markers.
- AcroForm support -- opt-in interactive PDF form fields that map Swing input components to their PDF equivalents.
- Java 17 or later
- Apache PDFBox 3.x (pulled in automatically as a transitive Maven dependency)