Word to Picture

Convert Word to TIFF Document in Java

We widely use MS Word document for official and personal data storage. Its also one of the popular file format for official information storage and sharing in corporate, university, government organizations. However, we may have a requirement to prevent un-authorized users from making any changes to the document, so we can convert Word to Image and freely share them. So in this article, we are going to learn the steps on how to convert Word to TIFF document using Java Cloud SDK.

Word to Image Conversion API

As per the scope of this article, we are going to use Aspose.Words Cloud SDK for Java for Word to Image conversion. It’s a wrapper around Aspose.Words Cloud API providing the capabilities to create, edit or convert Word to PDF, Word to JPG, Word to HTML, and various other Supported File Formats. Now in order to use the SDK, please add following details in pom.xml of maven build type project.

<repositories> 
    <repository>
        <id>aspose-cloud</id>
        <name>artifact.aspose-cloud-releases</name>
        <url>http://artifact.aspose.cloud/repo</url>
    </repository>   
</repositories>

<dependencies>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-words-cloud</artifactId>
        <version>22.8.0</version>
    </dependency>
</dependencies>

After the JDK reference has been added to project, we need to create a free account over Aspose Cloud. Then lookup/create Client ID and Client Secret at Cloud Dashboard. Please skip this step if you have already subscribed over cloud dashboard.

Convert Word to TIFF Document in Java

In this section, we are going to convert Word to Image(TIFF) using Java code snippet. The source word document will be loaded from clouds storage and after the conversion, it will be saved in same cloud storage.

  • Firstly, create an object of WordsApi while passing Client ID and Client Secret as parameters
  • Secondly, read the Word document from the local drive using the File object
  • Thirdly, create the UploadFileRequest instance which requires File object as an argument
  • Now call the method uploadFile(…) to upload Word document to cloud storage
  • Create an object of GetDocumentWithFormatRequest(…) while providing input Word document name, output format as TIFF, and resultant file name
  • Finally, call the method getDocumentWithFormat(…) to convert Word to Image and save the output in Cloud storage.
Word to TIFF preview

Image1:- Word to TIFF Conversion preview

The sample Word document used in above example can be downloaded from test_multi_pages.docx and resultant TIFF document from Converted.tiff

Word into Picture using cURL Commands

In this section, we are going to use the cURL commands for Word into Picture conversion. Now the first step is to generate a JWT access token while executing the following command.

curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=bb959721-5780-4be6-be35-ff5c3a6aa4a2&client_secret=4d84d5f6584160cbd91dba1fe145db14" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"

Once we have JWT token, please the following command to load Word document from cloud storage and save into TIFF document. The resultant TIFF is also stored in cloud storage.

curl -v -X GET "https://api.aspose.cloud/v4.0/words/Resultant.docx?format=TIFF&outPath=converted.tiff" \
-H  "accept: application/octet-stream" \
-H  "Authorization: Bearer <JWT Token>"

Conclusion

We have learned the details on how to convert Word to picture (TIFF) using Java Cloud SDK. At the same time, we have also leared Word to image using cURL Commands. Please note that as our SDKs are built under an MIT license, so the complete source code can be downloaded from GitHub. Apart from these options, the API can also be explored within web browser using SwaggerUI. In case you encounter any issues while using the APIs, please feel free to contact us via the product support forum.

We highly recommend visiting the following links to learn more about: