How to Convert Word DocX To PNG Image Array
Word DocX documents are essentially designed to be viewed (and edited) by people operating in a Microsoft ecosystem. Such documents utilize a proprietary editing format, making it difficult for users on other platforms to view the information they contain. An easy way around this problem is to convert each page of a Word Document into a PNG image, and share that file instead. You can’t edit a PNG file of course, but you can easily store it and use it as a lightweight alternative to converting DocX files into other formats.
Our DocX to PNG Array conversion API make this simple conversion task easy, automatically screenshotting and saving each page of a DocX file as a PNG Image, and subsequently saving those images in an array. Let’s look at how you can structure your API call easily using ready-to-run code examples in Java.
To get started, you’ll first need to install the Java SDK with Maven. First, use the below reference in the pom.xml repository:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
After that, let’s add a reference to the pom.xml dependency:
<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v4.25</version>
</dependency>
</dependencies>
Now let’s finish by including the remaining code block below:
// 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 {
DocxToPngResult result = apiInstance.convertDocumentDocxToPng(inputFile);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling ConvertDocumentApi#convertDocumentDocxToPng");
e.printStackTrace();
}
All that’s left now is to include your API key, which can be easily attained by registering a free account on our website. Your free-tier key will provide a limit of 800 API calls per month, and can be used to access dozens of other Cloudmersive utility APIs.