Word to JPG

Convert Word to JPG | Word into Image conversion Online

In this article, we are going to discuss the conversion of Word to JPG format. We understand that MS Word files (DOC, DOCX, DOCM, DOTX, ODT, OTT, etc) are quite popular for information storage and sharing in organizations, universities, and other institutes. They are also used in creating and designing business cards, brochures, new letters, and many more items. But even in order to view them, we need specialized software, so the conversion to raster images (JPG) can be a viable solution. It also generates compressed output in the form of a JPG image.

Let’s discuss the following topics in further detail.

Word to JPG Conversion API

Aspose.Words Cloud provides the capabilities to create, edit, and render MS Word or OpenOffice to other popular formats. Now as per the scope of this article, we need to use Aspose.Words Cloud SDK for .NET which is available for download at NuGet and GitHub. Please execute the following command in the terminal:

nuget install Aspose.Words-Cloud

Or execute the following command in NuGet Package Manager:

PM> Install-Package Aspose.Words-Cloud

Another approach is the direct installation within Visual Studio

After installation, we need to create a free account by visiting Aspose.Cloud dashboard. Use your GitHub or Google account or simply Sign Up to obtain your Client Credentials.

Convert Word to JPG in C#

Please follow the steps given below to convert Word to JPG using C# .NET:

  • First of all, we need to create an object of the Configuration class
  • Secondly, initialize the WordsApi instance while passing the Configuration object as an argument
  • Thirdly, read the content of the Word file and upload it to cloud storage using UploadFile(..) method
  • Now create an instance of GetDocumentWithFormatRequest and pass the name of the input Word file, output format, and resultant file name as arguments
  • Finally, call the GetDocumentWithFormat(…) method of WordsApi to perform the conversion. The resultant JPG is then stored in cloud storage
Word to JPG  conversion preview

Image 1:- Word to JPG conversion preview.

DOCX to JPG in C#

Let’s discuss the scenario where you want to perform DOCX to JPG conversion without uploading the source word file to Cloud storage. Please follow the steps specified below to accomplish this requirement.

  • First of all, we need to create an object of the Configuration class
  • Secondly, initialize the WordsApi instance while passing the Configuration object as an argument
  • Now create an instance of ConvertDocumentRequest which takes input DOCX path, output format, and resultant file name as arguments
  • Finally, call the ConvertDocument(..) method to initialize the conversion process. Resultant file is stored in Cloud storage

Word into Image using cURL Commands

Let’s explore the option to convert word into image format using cURL commands over the command line terminal. So the first step is to generate a JSON Web Token (JWT) based on ClientID and ClientSecret details retrieved from Aspose.Cloud dashboard. Please execute the following command in the terminal to generate the JWT token.

curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=4ccf1790-accc-41e9-8d18-a78dbb2ed1aa&client_secret=caac6e3d4a4724b2feb53f4e460eade3" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"

Once the JWT token has been generated, please execute the following command to convert Word into Image format.

curl -X GET "https://api.aspose.cloud/v4.0/words/sample1.doc?format=jpg&outPath=Converted.jpg&fontsLocation=fonts" \
-H  "accept: application/octet-stream" \
-H  "Authorization: Bearer <JWT Token>"

The sample files used in the above examples can be downloaded from sample1.docx and converted.jpg.

Conclusion

This article has explained the steps on how to convert Word to JPG using the C# .NET code snippet. We have also learned how to save Word into Image format using the cURL commands. In case you wish to modify the source code of Cloud SDK as per your requirements, you can download it under the MIT license from GitHub.

In case you encounter any issues while using the API, please feel free to contact us via the Free support forum.

We also recommend visiting the following link to learn more about