Java Words developers can easily insert an image into a DOCX document using the Aspose.Words Cloud REST API. This guide walks you through the process of adding a picture to a Word file online with the Java Low‑Code API, covering the key properties you can set to customize the image before it is placed in the document. For more details on the DOCX format, see the DOCX file information page. You can also use image files such as PNG as the source.
Prerequisite
- Create an account and get API credentials
- Download the Aspose.Words Cloud SDK for Java to add images in a Word file
- Set up a Java project and add the SDK as a dependency
Steps to Add a Picture to Word Document with Java REST API
- Initialize the WordsApi object with your client ID and client secret.
- Create an InsertDrawingObjectOnlineRequest, providing the source Word file bytes and the desired output file name.
- Instantiate a DrawingObjectInsert object and configure the image’s characteristics (size, position, wrap type, etc.).
- Assign the target image file to the request object.
- Call the InsertDrawingObjectOnline method to insert the image into the Word document.
- Retrieve the resulting document from the response and save it using the Document.TryGetValue() method.
The steps above outline the complete workflow for adding a picture to a Word document via the Java REST API. By constructing the InsertDrawingObjectOnlineRequest with the appropriate parameters—input document, output name, image dimensions, placement, and image file—you can programmatically embed images into your Word files.
Code to Add Photo to Word Document with Java REST API
Use this sample to add multiple photos to a Word document with the Java REST API. You can adjust margins, page numbers, column placement, wrap type, height, width, and more. Additional options include setting a password, encryption password, revision author, and revision date/time.
In this article we covered how to insert an image into a Word file. To learn how to add a watermark to a Word document, see the related article: Add a watermark in Word with Java REST API.
Keywords: insert picture into word document with Java Low Code API; add image in word document with NET REST API; add image to word document online with Java Low Code API; add picture to word document with NET REST API; add multiple photos to word document with Java REST API.