Kotlin: HTML/CSS to Image
Generate Images and PDFs with Kotlin. Renders exactly like Google Chrome.
Render PNG, JPG, or WebP images + PDFs with Kotlin from HTML/CSS or reusable dynamic templates.
Generating images with Kotlin
- The API takes your HTML/CSS and runs it inside a real instance of Google Chrome to convert your HTML into an image.
- Use Kotlin to send the API your HTML/CSS.
- You’ll get back JSON with the URL to your generated image.
For more details on how this works, see Creating an image.
Example API response:
{
"url": "https://hcti.io/v1/image/be4c5118-fe19-462b-a49e-48cf72697a9d",
"id": "be4c5118-fe19-462b-a49e-48cf72697a9d"
}

Authentication with Kotlin
The API uses HTTP Basic authentication.
Your username is your User ID and your password is your API Key. Both of these are available from the dashboard. The Kotlin code sample demonstrates how to authenticate your request.
You can sign up for a free API key to get started.
Kotlin example code
This Kotlin code example sends an HTTP POST to the https://hcti.io/v1/image API to convert your HTML/CSS to an image.
This example uses the built-in Java 11+ HttpClient from Kotlin and kotlinx.serialization to encode the JSON request body.
Add the JSON serialization dependency:
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.3")
}
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import java.net.URI
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse
import java.nio.charset.StandardCharsets
import java.util.Base64
fun main() {
val userId = "your-user-id"
val apiKey = "your-api-key"
val payload = mapOf(
"html" to "<div class='box'>Kotlin ✅</div>",
"css" to ".box { border: 4px solid #03B875; padding: 20px; font-family: Roboto, sans-serif; }",
"google_fonts" to "Roboto"
)
val body = Json.encodeToString(payload)
val auth = Base64.getEncoder().encodeToString(
"$userId:$apiKey".toByteArray(StandardCharsets.UTF_8)
)
val request = HttpRequest.newBuilder()
.uri(URI.create("https://hcti.io/v1/image"))
.header("Authorization", "Basic $auth")
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(body))
.build()
val response = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString())
if (response.statusCode() !in 200..299) {
error("Request failed: ${response.statusCode()} ${response.body()}")
}
println(response.body())
// {"url":"https://hcti.io/v1/image/1113184e-419f-49f1-b231-2069942a186f"}
}
Need help?
Talk to a human. Please email us support@htmlcsstoimage.com with any questions and we’ll gladly help you get started.