Export any Android View to a PNG, JPEG or multi-page PDF. Pure Kotlin on the Android SDK, no third-party libraries.
- 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.PdfDocumentandCanvas, nothing to add to your dependencies
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.
Open in Android Studio, or run ./gradlew assembleDebug (JDK 17+, Android SDK 37).
Issues and pull requests are welcome.
