Skip to content

About

Export any Android View to PNG, JPEG or multi-page PDF in Kotlin. Native PdfDocument, no third-party libraries, no storage permission.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

Android View to Image and PDF

Export any Android View to a PNG, JPEG or multi-page PDF. Pure Kotlin on the Android SDK, no third-party libraries.

Demo

Features

  • Save a view as PNG, JPEG or PDF, or share it as an image
  • Long views are split into A4 pages in the PDF, text stays sharp (vector)
  • Uses the system file picker (CreateDocument), so no storage permission is needed
  • Built on android.graphics.pdf.PdfDocument and Canvas, nothing to add to your dependencies

Usage

Copy ViewExporter.kt into your project:

ViewExporter.saveAsImage(context, uri, view, Bitmap.CompressFormat.PNG)
ViewExporter.saveAsPdf(context, uri, view)
val bitmap = ViewExporter.toBitmap(view)

Each save returns true on success. Get the uri from ActivityResultContracts.CreateDocument (see MainActivity.kt), or from a FileProvider to share.

Build

Open in Android Studio, or run ./gradlew assembleDebug (JDK 17+, Android SDK 37).

Feedback

Issues and pull requests are welcome.

About

Export any Android View to PNG, JPEG or multi-page PDF in Kotlin. Native PdfDocument, no third-party libraries, no storage permission.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages