Free tools Windows power users keep installed
One-click scans. No signup required.
To convert HTML to PDF in Spring Boot, use a template engine such as Thymeleaf to generate a complete, data-filled HTML document, then pass that document to a PDF renderer. For controlled XHTML-like templates, OpenHTMLtoPDF is one Java option. If your document relies on JavaScript or extensive modern CSS, evaluate a browser-backed renderer instead: a Java renderer does not automatically reproduce what Chrome displays.
The key decision is how browser-like your HTML needs to be. Keep document markup purpose-built, supply a base URI for relative resources, and test real examples for pagination, fonts, images, and layout before settling on a renderer.
How the conversion pipeline works
HTML-to-PDF conversion in a Spring Boot application has two distinct stages:
- Generate document HTML. A server-side template engine combines a template with application data, such as invoice lines, dates, and customer details. Spring Boot supports Thymeleaf and other engines, including FreeMarker, Groovy, and Mustache. Under the documented defaults, templates go in
src/main/resources/templates. See the Spring Boot template-engine reference and Thymeleaf documentation. - Render the HTML as PDF. A renderer interprets the resulting markup and styles and produces PDF bytes. Its HTML, CSS, JavaScript, font, and pagination support depends on the renderer; it is not a built-in property of Spring MVC.
This separation is useful: templates handle application data, while the renderer handles document layout and PDF output. Prefer a dedicated invoice, report, or letter template over feeding arbitrary user-provided markup directly into a renderer.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
Choose a renderer based on your HTML and CSS
First identify what the document actually uses: CSS layout, JavaScript-generated content, custom fonts, image formats, tables, page-break rules, Unicode, and right-to-left text. Then prototype representative documents with the candidate renderer. A result that looks acceptable on a short sample may fail on a long report or a page containing unusual fonts or images.
| Option | Useful when | Important limitations or checks |
|---|---|---|
| OpenHTMLtoPDF | Your input is controlled, well-formed XHTML-like markup and uses a supported CSS subset. | Targets a reasonable subset of well-formed XML/XHTML and some HTML5 with CSS 2.1 and later. It does not run JavaScript and lacks many modern standards, including flex and grid. Its project cautions that modern HTML/CSS should not be expected to render like a browser. The README says it requires Java 8 and reports testing on OpenJDK 8, 11, and 17 early access. It notes limited RTL support and no OpenType font support. Project README. |
| Flying Saucer Java renderer | Your document fits the capabilities of its Java rendering artifacts and you want a Java-based route. | Check the exact artifact, runtime requirement, markup and CSS support, and license for the version you select. The project documents Java 11+ from 9.5.0, Java 17+ from 9.6.0, and Java 21+ from 10.0.0. Project README. |
| Flying Saucer Chrome-backed PDF artifact | Modern HTML5/CSS3 or browser-style rendering matters enough to evaluate a browser-backed option. | Flying Saucer lists a Chrome-backed PDF artifact alongside its Java rendering artifacts. Confirm its setup, deployment requirements, and behavior for your own documents in the selected version’s documentation. Project README. |
Do not select by library name alone. Compare actual markup and CSS coverage, Java runtime and deployment footprint, JavaScript requirements, font and Unicode handling, pagination, accessibility or PDF/A needs, licensing, and output quality for representative files. The documentation does not establish a universal performance winner, so do not assume one without workload-specific measurement.
Build a Spring Boot PDF endpoint
The example below shows the application structure and the responsibilities at each stage. Renderer APIs vary by artifact and version, so the rendering call is intentionally marked as an integration point rather than presented as code verified against a specific dependency version. Use the selected renderer’s current documentation to implement that call and confirm its supported inputs.
1. Create a document template
For a Spring MVC application using Thymeleaf, put a template such as invoice.html in src/main/resources/templates. Keep the document self-contained enough for predictable rendering, and use well-formed markup if your renderer expects XML/XHTML-style input.
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Invoice</title>
<style>
body { font-family: sans-serif; font-size: 12pt; }
table { width: 100%; border-collapse: collapse; }
th, td { border: 1px solid #777; padding: 6px; }
</style>
</head>
<body>
<h1>Invoice <span th:text="${invoice.number}">INV-001</span></h1>
<p>Customer: <span th:text="${invoice.customerName}">Example Customer</span></p>
<table>
<thead><tr><th>Description</th><th>Amount</th></tr></thead>
<tbody>
<tr th:each="line : ${invoice.lines}">
<td th:text="${line.description}">Service</td>
<td th:text="${line.amount}">0.00</td>
</tr>
</tbody>
</table>
</body>
</html>
Adapt the document structure, escaping, and styling to your data and renderer. Avoid treating untrusted user input as template code or allowing a renderer to fetch arbitrary resources. If you load external images or stylesheets, consider which hosts and paths it can access.
2. Render the template into a complete HTML string
With Spring’s template infrastructure, supply a model and process the template before invoking the PDF engine. For Thymeleaf, a service can take the template name and context, then return the generated markup:
import org.springframework.stereotype.Service;
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.Context;
@Service
public class InvoiceHtmlService {
private final TemplateEngine templateEngine;
public InvoiceHtmlService(TemplateEngine templateEngine) {
this.templateEngine = templateEngine;
}
public String render(Invoice invoice) {
Context context = new Context();
context.setVariable("invoice", invoice);
return templateEngine.process("invoice", context);
}
}
Thymeleaf is a server-side Java template engine with Spring-specific integration material; see its official documentation. If the application already uses a different Spring-supported template engine, there is no requirement to switch solely for PDF generation.
3. Convert the HTML to PDF bytes
Pass the rendered HTML and a base URI to the chosen renderer. The base URI gives relative URLs, such as image and stylesheet paths, a location to resolve against. Exact APIs differ by library and release; follow the selected renderer’s documentation for its builder or document-loading calls.
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
public byte[] createPdf(Invoice invoice) {
String html = invoiceHtmlService.render(invoice);
String baseUri = resourceBaseUri();
try {
// Integration point: invoke the selected renderer's documented API.
// Supply html and baseUri; return the resulting PDF bytes.
return pdfRenderer.render(html, baseUri);
} catch (Exception ex) {
throw new PdfGenerationException("Could not generate invoice PDF", ex);
}
}
private String resourceBaseUri() {
// Return an application-controlled URI or path for document resources.
// The exact value depends on how the application packages those resources.
return configuredDocumentResourceBaseUri;
}
pdfRenderer, configuredDocumentResourceBaseUri, and PdfGenerationException are application-specific placeholders, not classes supplied by a named library. Replace them with a concrete adapter for the exact renderer version you selected. This avoids relying on an API signature that may differ between releases.
4. Return a PDF response
Expose the result with the PDF media type and a deliberate download filename. For example, an MVC controller can return bytes with headers:
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class InvoiceController {
private final InvoicePdfService pdfService;
public InvoiceController(InvoicePdfService pdfService) {
this.pdfService = pdfService;
}
@GetMapping(value = "/invoices/{id}/pdf", produces = MediaType.APPLICATION_PDF_VALUE)
public ResponseEntity<byte[]> downloadInvoice() {
byte[] pdf = pdfService.generateForCurrentInvoice();
return ResponseEntity.ok()
.contentType(MediaType.APPLICATION_PDF)
.header(HttpHeaders.CONTENT_DISPOSITION,
"attachment; filename="invoice.pdf"")
.body(pdf);
}
}
Wire the route to your application’s authorization and invoice lookup rather than exposing a fixed or caller-controlled document. For large PDFs, consider response streaming and resource limits; measure memory use with realistic documents instead of assuming the byte-array pattern suits every workload.
Test layout and resources before release
Build a small test set that exercises the document’s real features, then inspect the generated PDFs in a PDF viewer and, where relevant, compare text extraction or page counts:
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, 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 minuteRank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
- Short and long documents, including tables that span pages.
- Page breaks, headers, footers, margins, and landscape pages if used.
- Images and stylesheets loaded by relative paths, plus missing or slow resources.
- Custom fonts, accented characters, symbols, Unicode, and any right-to-left content.
- Repeated sections, empty values, unusually long labels, and text wrapping.
- The exact CSS constructs used by the template, especially if relying on modern layout.
Use a controlled resource base and handle failures explicitly. Decide what the endpoint should do if an image cannot load, a font is absent, or rendering throws an exception. Do not silently return a malformed or empty file as though PDF generation succeeded.
Dependency, runtime, and license checks
Before adding a renderer, confirm that the specific artifact works with the Java runtime used in development, tests, and production. Flying Saucer’s documented minimums vary by release: Java 11+ from 9.5.0, Java 17+ from 9.6.0, and Java 21+ from 10.0.0. OpenHTMLtoPDF’s README says it requires Java 8 and reports testing on OpenJDK 8, 11, and 17 early access; check its current project information for the release you plan to use.
Review licenses for the exact artifacts and their full transitive dependency trees against your distribution model. OpenHTMLtoPDF identifies PDFBox as its PDF library and states that its project is LGPL 2.1 or later. Flying Saucer’s README identifies LGPL 2.1 or later. Apache PDFBox identifies its own license as Apache 2.0 and announced version 2.0.37 on July 15, 2026. That PDFBox release fact does not by itself establish which PDFBox version a renderer will pull in; inspect the resolved dependency tree and the selected renderer’s documentation. Apache PDFBox.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Troubleshooting common conversion failures
- The result is unstyled or missing images: relative resource paths may have no usable base URI, or resources may not be accessible from the renderer. Supply an application-controlled base URI, verify the resolved paths, and check resource-loading errors.
- Layout differs from the browser: a Java renderer may support only a subset of HTML and CSS. Check whether the template uses flex, grid, JavaScript, or other unsupported features; simplify the print layout or evaluate a browser-backed route.
- Content disappears or is stale: JavaScript is not run by OpenHTMLtoPDF. Generate the required content on the server before rendering, or use a renderer that supports the browser behavior your page depends on.
- Pages break awkwardly: inspect long tables, oversized images, and print styles in multi-page examples. Adjust document structure and supported page-break styling, then verify the output at the actual page size.
- Characters or fonts are wrong: confirm font availability and encoding, and check the renderer’s font-format and Unicode support. OpenHTMLtoPDF notes no OpenType font support and limited RTL support, so verify those requirements before choosing it.
- The application fails at startup or compilation: check the Java version against the exact artifact release, resolve dependency conflicts, and inspect the complete transitive dependency tree.
- The endpoint returns an error or empty output: log rendering exceptions and resource-loading failures, validate the generated HTML, and ensure the controller only returns bytes after rendering completes successfully.
Or skip the browser setup
If the requirement is to capture an existing public web page rather than render an application document from a Spring template, ScreenshotNeo offers a website screenshot API and MCP server. Its API can return PNG, JPEG, WebP, or PDF. It is a different approach from generating invoices or reports from Thymeleaf data: use it when a URL is the input.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsBest Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
One GET request can return a PDF for a URL. For example, using cURL:
curl -G "https://api.screenshotneo.com/v1/shot"
-d access_key=YOUR_API_KEY
--data-urlencode url=https://stripe.com
-d format=pdf
-o page.pdf
See the ScreenshotNeo API documentation for authentication and PDF options. ScreenshotNeo’s documented features include accepting cookie or consent banners and removing more than 60 known consent platforms, newsletter popups, and chat widgets before capture; those steps can each be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, with page-verdict and billing information in response headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients.
The free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000. Sign up for ScreenshotNeo free.
Frequently Asked Questions
Can I convert an HTML string without creating a template file?
Yes. The rendering stage can accept generated markup; a template is a maintainability choice for documents populated with application data, not a requirement of PDF output.
Does Spring Boot itself provide a PDF renderer?
Spring Boot supports web applications and template engines, but HTML-to-PDF rendering is handled by a separate library or browser-backed service.
Is PDFBox alone an HTML-to-PDF converter?
PDFBox is a Java library for working with PDF documents; the cited project material does not position it as an HTML/CSS renderer.
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.

