I created a Microsoft Word document and tried to write the buffered image to it but all I got was garbled text. Is there a way to write (preferably append) a buffered image to a doc or RTF file?
I want to avoid using docx4j or iText or any external package for that matter due to some constraints. But if there is no other way then please do let me know.
My code in case anyone needs for reference:
ps_file = new File("ps_file.doc");
ImageIO.write(i1, "jpg", ps_file);
Word Documents have their own syntax to store their data so you can’t just append text to them and expect it to just work.
You will have to use a 3rd party library unless if you’re willing to reinvent the car.
You can however create an RTF file which stores the image. There’s a question similar to it that’s been answered here:
Programmatically adding Images to RTF Document
Obviously it’s for C# but the same procedures can easily be applied in Java.