Convert an EML File to PNG in Java
Due to the nature of the EML format, it can be a bit difficult to work with. Converting an EML file to a more versatile format, such as PNG, is generally an easier situation. In this quick tutorial, we will demonstrate how you can use an API in Java to instantly convert an EML file to an array of PNG images, one for each page.
We will begin the process in Maven by adding a reference to the repository in pom.xml:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Next, we will add a reference to the dependency:
<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v3.90</version>
</dependency>
</dependencies>
Now, we’re ready to call the conversion function with the following code:
// 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.ConvertDocumentApi;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");ConvertDocumentApi apiInstance = new ConvertDocumentApi();
File inputFile = new File("/path/to/inputfile"); // File | Input file to perform the operation on.
try {
EmlToPngResult result = apiInstance.convertDocumentEmlToPng(inputFile);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling ConvertDocumentApi#convertDocumentEmlToPng");
e.printStackTrace();
}
Your new PNG file will be ready for download in seconds flat! To retrieve your API key, head over to the Cloudmersive website to register for a free account; this provides 800 calls/month across any of our APIs.