Java getting started

Generate PDF bytes
from Java

Install one JAR and run the native Rust renderer inside your JVM process.

Java 17+ · Maven Central · Linux, macOS, Windows

Install from Maven Central

Add the artifact to any Java 17 or newer Maven project. The JAR selects the native asset for the current platform.

<dependency>
  <groupId>io.github.gastongouron</groupId>
  <artifactId>ironpress</artifactId>
  <version>1.5.4</version>
</dependency>

The package supports Linux x86-64 and ARM64 with glibc 2.28 or newer, macOS x86-64 and ARM64, and Windows x86-64.

Create an HTML PDF

import io.github.gastongouron.ironpress.HtmlConverter;
import java.nio.file.Files;
import java.nio.file.Path;

try (var converter = new HtmlConverter()) {
    byte[] pdf = converter.convertHtml(
        "<h1>Hello from Java</h1>"
    );
    Files.write(Path.of("output.pdf"), pdf);
}
Deterministic ownership

The converter implements AutoCloseable. A try-with-resources block releases its native handle even when conversion fails.

Render Markdown

The same configured converter accepts Markdown and returns an owned byte array:

byte[] pdf = converter.convertMarkdown(
    "# Release notes\n\nEverything shipped."
);

Reuse a configured converter

Configuration methods return the same converter, so related page and quality choices remain readable together.

try (var converter = new HtmlConverter()
        .setPageSize(PageSize.LETTER)
        .setMargins(PageMargins.ofPoints(36, 36, 48, 36))
        .setCompression(true)
        .setImageResolution(144)
        .setSanitization(true)
        .setHeader("Quarterly report")
        .setFooter("Page {page} of {pages}")) {
    byte[] first = converter.convertHtml(firstDocument);
    byte[] second = converter.convertHtml(secondDocument);
}

Provide fonts as bytes

The Java API accepts custom TrueType fonts and optional CJK or emoji packs as bytes. It never downloads a font implicitly.

try (var converter = new HtmlConverter()
        .addFont("MyFont", Files.readAllBytes(Path.of("MyFont.ttf")))
        .addFontPack(
            FontPackKind.CJK_JAPANESE,
            Files.readAllBytes(Path.of("ironpress-font-cjk-jp.ttf")))) {
    // Render documents with the configured fallback pack.
}

Handle failures and runtime limits

Renderer failures throw IronpressException. Its Kind keeps the stable parse, layout, render, font, security, or argument category.

  • HTML sanitization is enabled by default.
  • Calls on the same converter, including close, must not overlap.
  • Local paths, direct file output, async, streaming, and remote HTTP are absent.
  • The JAR verifies ABI generation 1 and the exact package version before allocating a converter.

Go further