https://github.com/jksalcedo/compose-to-pdf
Generate PDF from your Jetpack Compose UI Code
https://github.com/jksalcedo/compose-to-pdf
android-library compose jetpack-compose kotlin pdf-document-processor pdf-generation
Last synced: about 1 month ago
JSON representation
Generate PDF from your Jetpack Compose UI Code
- Host: GitHub
- URL: https://github.com/jksalcedo/compose-to-pdf
- Owner: jksalcedo
- Created: 2025-11-22T11:23:19.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-11-22T11:39:49.000Z (8 months ago)
- Last Synced: 2025-11-22T13:15:17.724Z (8 months ago)
- Topics: android-library, compose, jetpack-compose, kotlin, pdf-document-processor, pdf-generation
- Language: Kotlin
- Homepage:
- Size: 93.8 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ComposeToPdf
[](https://jitpack.io/#jksalcedo/compose-to-pdf)
**Generate PDF from your Jetpack Compose UI Code**
No XML layouts. No HTML conversion. Just pure Compose.
## Features
- Native: Uses Android's native PdfDocument.
- Vector: Content are vectors, not pixelated (except for images)
- Multi-Page: Simple API to generate multi-page documents.
- Invisible: Renders in the background without disturbing the UI.
- Asynchronous: Supports asynchronous image loading.
- Page Size: Supports all standard page sizes (A*, B*, etc.).
- Custom timeouts
- Custom page size
- Page Orientation
## Installation
Add the JitPack repository to your build file:
```kotlin
repositories {
maven { url = uri("https://jitpack.io") }
}
```
Add the dependency to `app/build.gradle.kts`:
```kotlin
dependencies {
implementation("com.github.jksalcedo:compose-to-pdf:1.1.0")
}
```
## Usage
```kotlin
val file = File(it, "test.pdf")
val outputStream = FileOutputStream(file)
val result = pdfGenerator.generate(
outputStream = outputStream,
pageSize = PdfPageSize.A4(72) // with 72 dpi (defaultt)
.orientation(Orientation.LANDSCAPE), // new feature
margin = 160.dp, // new feature (1 inch)
pages = listOf({
Text(
text = content.text.toString()
)
}, {
PdfAsyncImage(
model = "https://www.pixelstalk.net/wp-content/uploads/2016/06/HD-images-of-nature-download.jpg",
contentDescription = ""
)
}
)
)
```