html-screenshot

Converts HTML markup into a `ByteArray` for generating receipt images. Supports local HTML rendering with coroutine-based asynchronous architecture and uses platform callbacks for completion detection.

Android JVMKotlin/Native
GitHub stars0
Open issues0
LicenseApache License 2.0
Creation date10 months ago

Last activity10 months ago
Latest release0.0.1-alpha01 (10 months ago)

HTML Screenshot

A Kotlin Multiplatform Mobile (KMM) library for converting HTML markup into a ByteArray.


Overview

html-screenshot was created for the Tikbit application to enable the generation of receipt images from HTML. The library only handles local HTML-to-image conversion, meaning it does not support remote resources.


Features

  • Local HTML Rendering
    Accepts HTML as a string; no network requests or remote resources required.

  • Coroutine-Based Architecture
    Uses Kotlin coroutines for non-blocking, asynchronous rendering.

  • Rendering Callbacks
    Relies on platform callbacks (Android and iOS) to detect when rendering is complete, avoiding arbitrary time-outs.

Usage

val htmlContent = """
  <html>
    <body>
      <h1>Receipt</h1>
      <p>Amount: $19.99</p>
      <p>Date: 2025-05-04</p>
    </body>
  </html>
""".trimIndent()

private val imageConverter = HtmlToImageConverter(ScreenshotThatHtmlConfiguration(imageWidth = 480))
val result = imageConverter.convert(htmlContent)

when (result) {
    is Html2ScreenshotResult.Success -> {
        result.data
    }

    is Html2ScreenshotResult.Error -> {
        null
    }

    else -> null
}

Contributing

  1. Fork the repository.
  2. Create a feature or bug-fix branch.
  3. Submit a pull request with a clear description of changes.

Acknowledgments

Based on android-html2bitmap. Without their previous efforts this would've taken much longer to develop. Adapted to Kotlin coroutines and updated rendering logic to improve reliability.

Android JVMKotlin/Native
GitHub stars0
Open issues0
LicenseApache License 2.0
Creation date10 months ago

Last activity10 months ago
Latest release0.0.1-alpha01 (10 months ago)

HTML Screenshot

A Kotlin Multiplatform Mobile (KMM) library for converting HTML markup into a ByteArray.


Overview

html-screenshot was created for the Tikbit application to enable the generation of receipt images from HTML. The library only handles local HTML-to-image conversion, meaning it does not support remote resources.


Features

  • Local HTML Rendering
    Accepts HTML as a string; no network requests or remote resources required.

  • Coroutine-Based Architecture
    Uses Kotlin coroutines for non-blocking, asynchronous rendering.

  • Rendering Callbacks
    Relies on platform callbacks (Android and iOS) to detect when rendering is complete, avoiding arbitrary time-outs.

Usage

val htmlContent = """
  <html>
    <body>
      <h1>Receipt</h1>
      <p>Amount: $19.99</p>
      <p>Date: 2025-05-04</p>
    </body>
  </html>
""".trimIndent()

private val imageConverter = HtmlToImageConverter(ScreenshotThatHtmlConfiguration(imageWidth = 480))
val result = imageConverter.convert(htmlContent)

when (result) {
    is Html2ScreenshotResult.Success -> {
        result.data
    }

    is Html2ScreenshotResult.Error -> {
        null
    }

    else -> null
}

Contributing

  1. Fork the repository.
  2. Create a feature or bug-fix branch.
  3. Submit a pull request with a clear description of changes.

Acknowledgments

Based on android-html2bitmap. Without their previous efforts this would've taken much longer to develop. Adapted to Kotlin coroutines and updated rendering logic to improve reliability.

Survey iconComplete survey to improve klibs.io ↗
Let’s go