How to Generate an Image of Handwriting From Text Input with Java

2 min readMay 6, 2022


Pretty amazing what you can do with Deep Learning, right? Our Handwriting API can take input text and return a PNG file with “Handwritten” text specified in the input parameters. You can also specify the target width & stroke width for the handwriting.

You can use this API for free by following instructions below to implement ready-to-run code in Java, and creating a free account on our website (Home — Cloudmersive APIs) to receive your Cloudmersive API key.

Kick things off by installing the Java SDK with Maven. First, add a reference to the repository found in pom.xml:


Next, add one to the dependency found in pom.xml:


Lastly, include the import classes and call the image processing function:

// Import classes:
//import com.cloudmersive.client.invoker.ApiClient;
//import com.cloudmersive.client.invoker.ApiException;
//import com.cloudmersive.client.invoker.Configuration;
//import com.cloudmersive.client.invoker.auth.*;
//import com.cloudmersive.client.TextGenerationApi;
ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: Apikey
ApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");
Apikey.setApiKey("YOUR API KEY");
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
TextGenerationApi apiInstance = new TextGenerationApi();
CreateHandwritingRequest request = new CreateHandwritingRequest(); // CreateHandwritingRequest | Draw text parameters
try {
Object result = apiInstance.textGenerationCreateHandwritingPng(request);
} catch (ApiException e) {
System.err.println("Exception when calling TextGenerationApi#textGenerationCreateHandwritingPng");

And just like that, you’re all done.




There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.