Skip to content

Generate PDFs from your Jetpack Compose UI Code

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE_HEADER
Notifications You must be signed in to change notification settings

jksalcedo/compose-to-pdf

Repository files navigation

ComposeToPdf

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:

repositories {
    maven { url = uri("https://jitpack.io") }
}

Add the dependency to app/build.gradle.kts:

dependencies {
    implementation("com.github.jksalcedo:compose-to-pdf:1.1.0")
}

Usage

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 = ""
        )
    }
    )
)

About

Generate PDFs from your Jetpack Compose UI Code

Topics

Resources

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE_HEADER

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Languages