The whole integration
The JDK’s own HTTP client is enough. BodyHandlers.ofFile writes the PDF without buffering it all in memory.
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.
