A Compose Multiplatform library for exporting UI content to vector PDFs across Android, iOS, and JVM/desktop.
- Render any
@Composableto a multi‑page PDF (vector output). - Automatic pagination based on measured height.
- Optional item‑based pagination to keep blocks together.
- Custom page formats (
A4,Letter,Custom, etc.) and orientation. - Consistent output with Compose layouts and styling.
- Android (minSdk 26)
- iOS (iosX64, iosArm64, iosSimulatorArm64)
- JVM (desktop)
kotlin {
sourceSets {
commonMain.dependencies {
implementation("de.charlex.compose:multiplatform-pdf-export:<version>")
}
}
}Use the version shown in the Maven Central badge above.
val pdfBytes = renderComposeToPdf(
context = PdfContext(),
format = PdfFormat.A4,
orientation = PdfOrientation.Portrait
) {
Column {
Text("Hello PDF")
// ... long content
}
}val pdfBytes = renderComposeToPdf(
context = PdfContext(),
format = PdfFormat.A4,
orientation = PdfOrientation.Portrait
) {
item { Header() }
items(data) { row -> RowItem(row) }
item { Footer() }
}// Android
val pdfBytes = renderComposeToPdf(
context = PdfContext(activity),
content = { /* ... */ }
)
// iOS / JVM
val pdfBytes = renderComposeToPdf(
context = PdfContext(),
content = { /* ... */ }
)- Android: renders directly to
android.graphics.pdf.PdfDocument. - iOS: renders to SVG and draws into CoreGraphics PDF context.
- JVM: renders to SVG and converts to PDF (Batik/FOP), then merges pages (PDFBox).
PDF output uses the Compose rendering stack. If you need identical typography across platforms, consider providing explicit fonts in your Compose theme (instead of relying on system defaults).
See sample/ for Android, iOS and JVM examples.
MIT — see LICENSE.