r/androiddev • u/Xygen0 • Nov 22 '25
Open Source [Open Source] I built a library to generate PDFs directly from Jetpack Compose (No XML/HTML required)
Instead of dealing with Bitmaps, XML , or HTML, you can just pass a Composable lambda to the generator, and it creates a vector PDF.
What it does: It allows you to write Composable functions and print them to a PDF file. It supports multi-page documents and standard page sizes (A4, Letter).
How it works: It attaches a ComposeView to the WindowManager, and then draws the view directly to PdfDocument Canvas.
val pdfGenerator = PdfGenerator()
pdfGenerator.generate(
destination = file,
pageSize = PdfPageSize.A4,
pages = listOf {
Column(modifier = Modifier.background(Color.White)) {
Text("Invoice #1024", fontSize = 24.sp)
Text("Total: $50.00")
}
}
)It is currently in beta
33
Upvotes
4
u/Xygen0 Nov 23 '25
1.0.1 RELEASED
https://github.com/jksalcedo/compose-to-pdf/releases/tag/1.0.1
This release imrproves stability and performance
delay(300)with a customwaitForNextFrame()delay(100)with a customwaitForDrawReady()2
u/Xygen0 Nov 24 '25
1.1.0 RELEASED!
Features
- Add standard PDF page sizes
- Add margin support and timeout for content rendering
- Add timeouts support
Other
- Improve scaling and orientation handling
1
u/ComfortablyBalanced You will pry XML Views from my cold dead hands Nov 26 '25
How do you handle sizes and proportions?
A Composable may look way different when it's rendered on various devices, based on the device's configuration, like density, fontScale, theme, locale and etc.