Skip to content

HTML to PDF in Kotlin With OpenHTMLToPDF, iText or an API and What a Year Costs

Kotlin teams pick between a JVM layout library with CSS limits and a license to read, or a browser. At 30,000 documents a month the API route costs about $988 in year one against about $4,400 for a self-run browser.

Live demo

Runs in your browser. Nothing is uploaded. One PDF free to try, then a plan.

Your PDF is downloading. That was the free one. The Starter plan converts as many as you need, for $49 a month or $288 a year, half price.

See the plan

SitePDF is an HTML to PDF API, and this article answers the question a Kotlin team asks before choosing a route: what does it cost to turn HTML into PDF on the JVM, and when is an API call cheaper than a library or your own browser. The short answer is that JVM libraries are cheap to start but stop at CSS 2.1 style layouts, and the moment invoices use flexbox or web fonts you need a browser engine, run by you or by someone else.

The short answer

For a plain table invoice with no modern CSS, OpenHTMLToPDF is a sensible free choice. For HTML that must match the web view, use a Chromium based renderer. From Kotlin that means Playwright for Java in your own container, or a rendering API called with OkHttp, Ktor or the JDK HttpClient. iText can convert HTML too, but its current versions are licensed under the AGPL or a paid commercial license, so check that before it reaches production.

What are the real options for HTML to PDF in Kotlin?

RouteWhat you operateModern CSS (flexbox, grid, web fonts)Licence to check
OpenHTMLToPDF or Flying SaucerA JAR in your appLimited, built around CSS 2.1 and strict XHTMLLGPL
iText with pdfHTMLA JAR, plus a licence decisionPartial, its own layout engineAGPL or commercial
Playwright for JavaChromium in your image, a pool, fonts, timeoutsYes, same engine as the browserApache 2.0
Rendering API over HTTPAn API key and one requestYes, managed ChromiumCommercial, priced by renders

The practical split is simple. A JVM library keeps everything in one process and needs no new infrastructure, which is why it is the right first try. The trouble starts when a designer hands over an invoice with a CSS grid summary box, and the output shows the boxes stacked or missing.

Why does iText licensing matter for a SaaS?

The AGPL requires that you offer the source of your application to its users if you run modified or linked AGPL code as a network service. Most SaaS companies do not want that, so they buy a commercial license. That is a legal and budget decision, not a technical one, and it is better made before the code ships. The iText licensing page explains the options, and the iText license cost breakdown works through the numbers for .NET, which apply the same way to the JVM.

What does running Chromium from the JVM involve?

Playwright for Java launches a headless Chromium, opens a page, sets your HTML and calls the print method. The code is short.

// Kotlin, Playwright for Java
Playwright.create().use { pw ->
    val browser = pw.chromium().launch()
    val page = browser.newPage()
    page.setContent(invoiceHtml)
    val pdf = page.pdf(Page.PdfOptions().setFormat("Letter"))
    File("invoice.pdf").writeBytes(pdf)
}

In production the container needs the browser and its system libraries, fonts for every script your customers use, a cap on concurrent pages so a billing-day batch does not exhaust memory, and a restart policy for a hung browser. A slim JRE image grows by several hundred megabytes, and a Spring worker that also serves web traffic should not share a pod with it. The HTML to PDF in Spring Boot page covers the integration side.

What does it cost in year one at 30,000 documents a month?

These are planning assumptions, not measurements, so replace them with your own. A team renders 30,000 invoices and statements a month. They spend 20 hours building the Playwright worker, font set and monitoring, then 2 hours a month on upgrades and incidents, at $100 an hour. They run a separate worker container at $40 a month.

ItemBasisYear one cost
Build the Playwright worker20 hours at $100$2,000
Upgrades and incidents2 hours a month at $100$2,400
Worker container$40 a month$480
Self-hosted total$4,880
Integrate the API from Kotlinabout 4 hours at $100$400
SitePDF Growth, 50,000 renders a month$99 list, $588 billed yearly$588
API total$988

Only the $588 repeats in year two, while the self-hosted labor and container repeat in full. The figure to challenge is the maintenance time. If your platform team already operates a browser fleet, the marginal cost is lower and self-hosting can win. If a library such as OpenHTMLToPDF already gives you the output you need, none of this applies and you should keep it.

How do you call a rendering API from Kotlin?

With OkHttp it is one POST. Send the HTML you already produce with a template engine such as Thymeleaf or kotlinx.html, and get back a link to the PDF.

val body = """{"html": ${Json.encodeToString(invoiceHtml)}, "format": "Letter", "archive": true}"""
    .toRequestBody("application/json".toMediaType())
val request = Request.Builder()
    .url("https://api.sitepdf.com/v1/render")
    .header("Authorization", "Bearer ${System.getenv("SITEPDF_KEY")}")
    .post(body)
    .build()
val response = OkHttpClient().newCall(request).execute().use { it.body!!.string() }

The render runs in managed Chromium, so flexbox, web fonts and chart scripts behave as in your browser. With archive set to true the render is also stored with its capture time, which helps when a customer asks for an invoice from months ago. Archive retention is 90 days on Starter API, 365 on Growth and three years on Scale. See the PDF generator API page for the same flow in other stacks, and the SaaS page for plan sizing by account count.

Who this is for and who it is not for

It is for Kotlin and Java teams that produce invoices, statements or reports from HTML and would rather pay a flat monthly price than run a browser worker. It is not for teams that draw fixed-position forms in code, need PDF signing, or must keep all data inside their own network. For those, a JVM library or a self-hosted browser is the better route.

What to do this week

Building for Apple platforms as well? The HTML to PDF in Swift article covers the WKWebView route and its limits. Take your most complicated invoice and render it with your current library. If the layout holds, stay. If it breaks, send the same HTML through SitePDF from a short Kotlin test and compare. The pricing page shows the plan for your volume, and the Java PDF library comparison covers the library side in more depth.

If you use Flying Saucer or OpenHTMLToPDF from Java, the Flying Saucer and OpenHTMLToPDF cost article covers the XHTML and template side.

On a C++ stack the same choice appears with Qt WebEngine and CEF, priced in the C++ HTML to PDF cost comparison. A Delphi team faces the same trade with WebView2 or CEF4Delphi, priced in the Delphi HTML to PDF cost article.

Frequently asked questions

How do I convert HTML to PDF in Kotlin?

Use a JVM library such as OpenHTMLToPDF for simple layouts, or render in a browser engine for modern CSS. With a browser route you either run Playwright for Java yourself or POST the HTML to a rendering API and receive the PDF.

Does OpenHTMLToPDF support flexbox and CSS grid?

No. It targets CSS 2.1 with extensions for paged media and expects well-formed XHTML. Flexbox, grid and many modern properties are not supported, so templates written for a browser often need rework.

Is iText free for commercial use?

Not for closed-source network services. Current iText versions are AGPL or a paid commercial license. Read the license terms and decide before production, because the AGPL can require you to offer your application source.

When is an HTML to PDF API cheaper than self-hosting in Kotlin?

At steady volume with no existing browser fleet, because maintenance labor dominates. In the example above, 30,000 renders a month cost $988 in year one through the API against $4,880 self-hosted, using stated assumptions.

Written by the team behind SitePDF, an HTML to PDF API that archives every page it renders. The in-browser converter is free to try, and API plans start at $49 a month, half price billed yearly.

Get started

Render and archive with one API call

A pixel perfect PDF and a dated copy of the page from the same request. Plans from $49 a month, half price billed yearly.

HTML to PDF, in your browser

Buy the plan