HTML to PDF in Java

Java 11+ HttpClient, no third-party jar. Spring Boot friendly, and the response streams straight to a file or an output stream.

HTML PDF PNG JPEG URL
No credit card required · 500 free renders/month

The whole integration

The JDK’s own HTTP client is enough. BodyHandlers.ofFile writes the PDF without buffering it all in memory.

Render.java
var body = """
    {"html":"<h1>Invoice #1042</h1>",
     "options":{"format":"A4","margin":"12mm"}}
    """;

var request = HttpRequest.newBuilder()
    .uri(URI.create("https://api.filecook.com/render/pdf"))
    .header("Authorization", "Bearer " + System.getenv("FILECOOK_API_KEY"))
    .header("Content-Type", "application/json")
    .POST(HttpRequest.BodyPublishers.ofString(body))
    .build();

HttpClient.newHttpClient().send(
    request,
    HttpResponse.BodyHandlers.ofFile(Path.of("invoice.pdf"))
);

The Java landscape

Flying Saucer renders XHTML with CSS 2.1 — dependable, but frozen a long way behind the modern web, and strict about well-formed input. iText is powerful and well maintained, but its AGPL licence means commercial use generally requires a paid licence, which is a procurement conversation rather than a technical one.

  • Current Chromium rendering, so CSS Grid and Flexbox behave normally
  • No AGPL obligations to reason about
  • No XHTML well-formedness requirement — send the HTML you actually have

Spring Boot

Render a Thymeleaf template to a string, post it, and return the bytes as a ResponseEntity with APPLICATION_PDF. For scheduled reporting, call it from a @Scheduled job and push the result to object storage.

Frequently asked questions

Does this work with Thymeleaf or Freemarker?
Yes. Any template engine that produces an HTML string works — render the template, then post the string.
Can I avoid buffering large PDFs in memory?
Yes. Use BodyHandlers.ofFile or ofInputStream to stream the response straight to disk or onward to storage.
Do you support modern CSS like Grid and Flexbox?
Yes. Filecook renders on the latest Chromium, so CSS Grid, Flexbox, custom properties, and modern selectors all behave exactly as they do in Chrome. If it looks right in your browser, it looks right in the PDF.
Do you store the documents you render?
No. Rendering happens in an isolated memory enclave and the output is discarded as soon as it has been returned to your request. Nothing is written to disk and nothing is retained.
Is there a free tier?
Yes — 500 renders a month, free forever, with no credit card required. That covers the playground, the full API, and both PDF and image output.

Keep reading

Ready to start cooking?

500 renders a month, free forever. No credit card, no sales call.