Use the URL to PDF Converter when you want the file without installing anything. The steps below are the detail.
OpenHTMLtoPDF converts HTML to PDF in Java without starting a browser. It lays out a subset of well-formed XML or XHTML with CSS 2.1 and writes a PDF through Apache PDFBox. The project says it is not a browser: it does not run JavaScript, and it does not implement flexbox or grid. Use it for a template you control. Use Playwright for Java when the page needs Chromium.
Which artifact to install
The original com.openhtmltopdf artifacts stopped at 1.0.10. The maintained line on Maven Central is io.github.openhtmltopdf. On 22 October 2026 the PDFBox module’s latest release was 1.1.100. That fork publishes often, so check Maven Central on the day you install and pin the version you actually download.
<dependency>
<groupId>io.github.openhtmltopdf</groupId>
<artifactId>openhtmltopdf-pdfbox</artifactId>
<version>1.1.100</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.23.2</version>
</dependency>
Jsoup 1.23.2 was the release on Maven Central on 24 October 2026. Confirm it the same way. The second dependency is only there to turn loose HTML5 into a document the renderer will accept. openhtmltopdf-pdfbox brings in the core module.
Convert an HTML string
Jsoup parses the HTML. W3CDom turns that into the DOM OpenHTMLtoPDF consumes. withW3cDocument takes that DOM and a base URI. The base URI resolves relative images and stylesheets. Use a file URI for local assets, or / when the document has none. useFastMode is the builder’s usual setup. run writes the PDF.
import com.openhtmltopdf.pdfboxout.PdfRendererBuilder;
import java.io.FileOutputStream;
import java.io.OutputStream;
import org.jsoup.Jsoup;
import org.jsoup.helper.W3CDom;
import org.w3c.dom.Document;
public class OpenHtmlToPdf {
public static void main(String[] args) throws Exception {
String html = """
<html>
<head>
<meta charset="utf-8">
<style>
@page { size: A4; margin: 16mm; }
body { font-family: sans-serif; font-size: 12pt; color: #222; }
h1 { font-size: 18pt; }
table { width: 100%; border-collapse: collapse; }
th, td { border: 1px solid #999; padding: 6px; }
tr { page-break-inside: avoid; }
</style>
</head>
<body>
<h1>October report</h1>
<p>Generated with OpenHTMLtoPDF.</p>
</body>
</html>
""";
Document dom = new W3CDom().fromJsoup(Jsoup.parse(html));
try (OutputStream os = new FileOutputStream("report.pdf")) {
PdfRendererBuilder builder = new PdfRendererBuilder();
builder.useFastMode();
builder.withW3cDocument(dom, "/");
builder.toStream(os);
builder.run();
}
}
}
The text block needs Java 15 or newer. Paper size in this library comes from @page. That is not true of every HTML-to-PDF tool.
CSS you have to write for this engine
The README is blunt. Flexbox and grid are not supported. Transparency is not supported, so replace rgba and opacity with a solid color. JavaScript does not run, so a chart drawn in the browser will be missing. Build the layout with tables, floats, or simple blocks, and keep the markup well formed.
Fonts that are not the PDF base fonts have to be registered on the builder for the run that needs them. Do that from the method on the version you pinned, rather than from a 2021 snippet that still imports com.openhtmltopdf 1.0.10.
When to use Chromium instead
A page that already works in Chrome, with flex, grid, or scripts, will not survive this renderer unchanged. HTML to PDF in Java with Playwright starts Chromium and calls page.pdf. iText is a separate license decision, not a drop-in for this builder.
Skip the install
The URL to PDF converter is the no-install path. It uses headless Chrome in screen mode, skips print-only CSS, and takes the paper size from the form rather than from @page. The file is deleted after download. There is no signup and no watermark.







