How can I add an Image stored in my local computer to a word file using Java code. Please let me know any API's that I can use. Or any sample code?
Asked
Active
Viewed 3,210 times
-1
-
possible duplicate of [Insert an image into a word document in Java](http://stackoverflow.com/questions/4941744/insert-an-image-into-a-word-document-in-java) – nathanchere Sep 22 '13 at 11:15
1 Answers
1
Consider Apache POI ApachePOI
POI is an API for manipulating MS office documents. Know more here:Duplicate ques
and one more duplicate question

Community
- 1
- 1

Sachin Verma
- 3,712
- 10
- 41
- 74
-
-
HI ..I used the code as mentioned in these links but i get the following error- Exception occurred during playback of script [ImagetoWord] [CRFCN0019E: RationalTestScriptException on line 53 of script ImagetoWord - org.apache.poi.POIXMLException: org.apache.poi.openxml4j.exceptions.InvalidFormatException: Package should contain a content type part [M1.13].]. – user2794731 Sep 22 '13 at 13:01
-
@ Sachin Verma i used this code CustomXWPFDocument document = new CustomXWPFDocument(new FileInputStream(new File("C:\\doc1.docx"))); FileOutputStream fos = new FileOutputStream(new File("C:\\doc3.docx")); String id = document.addPictureData(new FileInputStream(new File("C:\\a.jpg")), Document.PICTURE_TYPE_JPEG); document.createPicture(id,document.getNextPicNameNumber(Document.PICTURE_TYPE_JPEG), 64, 64); document.write(fos); fos.flush(); fos.close(); – user2794731 Sep 22 '13 at 13:02