Generate a PDF in Kotlin: OpenPDF and IronPDF

# kotlin# pdf# android# java
Generate a PDF in Kotlin: OpenPDF and IronPDFIronSoftware

A course platform written in Kotlin needs a completion certificate as a PDF, and one candidate is...

Every learner who finishes a course on a Kotlin-built platform receives a completion certificate as a PDF, and one candidate for producing it is OpenPDF with its Kotlin module. The number to settle before writing any code is 21, the Java version that OpenPDF's 2.1 and 3.0 lines require.

IronPDF for Java, which we build, is a released library that Kotlin code on the JVM can call, and our IronPDF for Kotlin is coming soon, with early-access sign-up, so the certificate starts in OpenPDF.

We work at Iron Software, and the end of this article covers our library, IronPDF.

How does OpenPDF build a certificate in Kotlin?

It builds the certificate from code through a Kotlin builder. OpenPDF is a Java library, licensed under the LGPL or the MPL, that creates, edits, renders and encrypts PDF documents, and openpdf-kotlin is a Kotlin module that adds a builder on top of it.

import com.github.librepdf.kotlin.PdfBuilder
import java.io.FileOutputStream

fun main() {
    // The use block closes the output stream when the builder finishes.
    FileOutputStream("certificate.pdf").use { output ->
        PdfBuilder(output).build {
            title("Certificate of Completion")
            subtitle("Kotlin Coroutines in Practice")
            paragraph("Awarded to Dana Reyes on completing all twelve modules.")

            // A named argument sizes the seal image.
            image("seal.png", scalePercent = 50f)
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

The listing reads like idiomatic Kotlin. On a Java 21 toolchain, it is the whole program.

Why does Java 21 matter for a Kotlin build?

It matters because the Kotlin module has only been published from version 2.1.0 onward, and every OpenPDF release from 2.1.0 to 3.0.6 requires Java 21 or later. A service on Java 21 meets that floor without effort. A build held at Java 17 does not, and its build file shows the conflict in three lines.

kotlin {
    // A toolchain pinned to 17 sits below the Java 21 floor of OpenPDF 2.1 through 3.0.
    jvmToolchain(17)
}
Enter fullscreen mode Exit fullscreen mode

On the project's tracker, one user asked for the Java target to move from 21 back to 17, and for records to be removed, because Android's D8 and R8 desugaring cannot handle java.lang.Record without extra configuration on the consumer's side. A contributor replied that the 2.0 branch supports Java 17 and pointed to OpenPDF 2.0.5, which means staying on an older branch.

Does OpenPDF run on Android?

Its own pages disagree. The repository's front page says OpenPDF can be used with Android. The Android page of its wiki says OpenPDF never supported Android, because the library relies heavily on java.awt and the Android SDK does not include those packages. The workaround given there, a third-party AWT library, is marked experimental, and in the Kotlin module, exploring Android or multiplatform compatibility is listed as a to-do item.

OpenPDF on a Java 21 server

On a server that already runs Java 21, OpenPDF brings more than the builder. Version 3.0.6 is published to Maven Central together with the Kotlin module under the same version number, so there is one number to track. Next to the builder, the Kotlin module carries an HtmlPdfBuilder for PDFs from HTML, a renderer module turns PDF pages into images or shows them in Swing and JavaFX applications, and encryption and editing are part of the library. Version 3.0.6 uses SecureRandom for encryption keys, salts and IVs, and version 3.0.5 added post-quantum signatures and SHA-3 digests.

What does the certificate look like through IronPDF for Java?

It is an HTML string that becomes a finished PDF in one call. IronPDF for Java ships for Java 8 and later, Kotlin included, on Linux, Windows, Mac and cloud platforms, so a Kotlin service on a Java 17 toolchain can use it without changing its build target.

import com.ironsoftware.ironpdf.PdfDocument

fun main() {
    // The certificate is plain HTML, so its layout lives in markup and not in builder calls.
    val html = "<h1>Certificate of Completion</h1><p>Dana Reyes completed Kotlin Coroutines in Practice.</p>"
    PdfDocument.renderHtmlAsPdf(html).saveAs("certificate.pdf")
}
Enter fullscreen mode Exit fullscreen mode

The PDF from that listing is one A4 page that carries the heading and the completion line, with no build change beyond the dependency.

A certificate may later need a signature or a filled form, and the IronPDF for Java examples cover signing the PDF and filling form data.

Android is where the dedicated edition comes in. According to its product page, IronPDF for Kotlin will let Android apps, and JVM back ends as well, create PDFs from HTML and edit existing ones from Kotlin code, with the engine inside the app and no server to call.

Splitting the move between the JVM and Android

The plan splits by where the code runs, because IronPDF for Java already serves the JVM and the Android route opens with the Kotlin edition.

  1. Read the build file first: note the jvmToolchain value in every module that produces PDFs.
  2. Move JVM services to IronPDF for Java: render the real certificate from its template file, compare it with the current output and switch each service once the PDF matches, with no change to the Java 17 target.
  3. Register Android apps for the Kotlin edition: sign up on the IronPDF for Kotlin page on ironpdf.com and keep the certificate template ready as the first test.
  4. Keep server templates shared: hold the certificate as one HTML template so the JVM service and the future Android app render the same file.

OpenPDF facts in this article are drawn from its own pages, tracker and published artifacts. On November 26, 2026, we ran the IronPDF listing, compiled with Kotlin 2.4.21 against com.ironsoftware:ironpdf 2026.11.3, and it produced a one-page certificate PDF on a Java 17 runtime. The first service we would move is the one whose toolchain is pinned to 17, tested with a trial key valid for 30 days.

Drafted with AI. On November 26, 2026, the IronPDF for Java listing was compiled with Kotlin 2.4.21 and run on Java 17 against com.ironsoftware:ironpdf 2026.11.3. The OpenPDF listing was compiled against openpdf-kotlin 3.0.6, its other claims were checked against the OpenPDF repository, wiki, issue tracker and Maven Central records, and the IronPDF for Kotlin claims against its product page.

OpenPDF, Kotlin, Java, Android, Swing, JavaFX, Linux, Windows and Mac are trademarks of their respective owners, we have no affiliation with any of them, and the facts above come from the OpenPDF repository, wiki, issue tracker and Maven Central records, the IronPDF for Java documentation, our run of the IronPDF for Java listing and the IronPDF for Kotlin page on ironpdf.com.