In a world where information comes in all forms, from scanned documents to images, the need to convert JPG to Word (DOC, DOCX) arises as a key solution for making content more accessible and editable. Imagine having a photo with text that you want to modify or share – that’s where JPG to Word conversion steps in. Let’s embark on a journey to develop JPG picture to Word converter using .NET REST API.
- REST API for Image to Word Conversion
- Convert JPG to Word in C# .NET
- Convert Photo to Word using cURL Commands
REST API for Image to Word Conversion
Aspose.Words Cloud SDK for .NET is a powerful and developer friendly solution providing the capabilities to convert JPG to Word format. The SDK provides comprehensive documentation, making it easy for you to integrate the necessary functionalities into your applications.
In order to use the SDK, the first step is to add its reference in project. So please search Aspose.Words-Cloud
in NuGet packages manager and click the Add Package
button. This will add the SDK reference in your project. Secondly, obtain your client credentials from cloud dashboard. If you do not have an existing account, simply create a free account by following the instructions specified in the quick start article.
Convert JPG to Word in C# .NET
Please follow the instructions given below to achieve a seamless conversion using C# .NET.
WordsApi wordsApi = new WordsApi(new Configuration()
{
ClientId = clientID,
ClientSecret = clientSecret
});
Create an object of WordsApi class where we pass the Configuration object as an argument.
CreateDocumentRequest createRequest = new CreateDocumentRequest("input.docx", null, null);
wordsApi.CreateDocument(createRequest);
Create a new blank Word document.
DrawingObjectInsert requestDrawingObject = new DrawingObjectInsert();
Create a drawing object and then define its margin as well as content alignment details.
InsertDrawingObjectRequest request = new InsertDrawingObjectRequest("input.docx", requestDrawingObject,
requestImageFile, "sections/0", null, null, null, null, null, "Resultant.docx", null, null);
Create an instance to InsertDrawingObject defining the node where Drawing object is to be placed.
wordsApi.InsertDrawingObject(request);
Finally, call the method to insert the Drawing object inside Word document and save the output to Cloud Storage.
Convert Photo to Word using cURL Commands
Achieving the conversion from JPG to Word using cURL commands with the Aspose.Words Cloud API provides a straightforward and command-line-driven approach. Utilizing cURL commands allows you to interact with the Aspose.Words Cloud API for this specific conversion seamlessly.
The first step in this approach is to generate a JWT access token using the following command:
curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=163c02a1-fcaa-4f79-be54-33012487e783&client_secret=c71cfe618cc6c0944f8f96bdef9813ac" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"
Now, please execute the following command to generate a blank Word document.
curl -v -X PUT "https://api.aspose.cloud/v4.0/words/create?fileName=input.docx" \
-H "accept: application/json" \
-H "Authorization: Bearer <JWT Token>"
Finally, call the following command to insert the drawing object in newly created Word document.
curl -v -X POST "https://api.aspose.cloud/v4.0/words/input.docx/sections/0/drawingObjects?destFileName={outputFile}" \
-H "accept: application/json" \
-H "Authorization: Bearer <JWT Token>" \
-H "Content-Type: multipart/form-data" \
-d {"drawingObject":"{ \"RelativeHorizontalPosition\": \"Margin\", \"Left\": 0, \"RelativeVerticalPosition\": \"Margin\", \"Top\": 0, \"Width\": 0, \"Height\": 0, \"WrapType\": \"Inline\"}","imageFile":{"source.jpg"}}
Replace outputFile
with the name of resultant Word document, and accessToken
with JWT access token generated above.
Conclusion
In this article, we have explored two seamless approaches for converting JPG images to Word document formats. We have learned that with SDK, you are equipped with a powerful and feature-rich toolkit, enabling seamless integration into .NET applications. On the other hand, utilizing cURL commands provides a quick and accessible command-line-driven alternative, suitable for users with varying technical backgrounds. Therefore, through the SDK’s versatility or the command-line convenience of cURL, you may develop a more efficient and tailored document processing workflow.
Useful Links
Related Articles
We highly recommend visiting the following blogs: