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

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:

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)
//Apikey.setApiKeyPrefix("Token");
TextGenerationApi apiInstance = new TextGenerationApi();
CreateHandwritingRequest request = new CreateHandwritingRequest(); // CreateHandwritingRequest | Draw text parameters
try {
Object result = apiInstance.textGenerationCreateHandwritingPng(request);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling TextGenerationApi#textGenerationCreateHandwritingPng");
e.printStackTrace();
}

And just like that, you’re all done.

--

--

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

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Cloudmersive

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