1

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);
Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
ritratt
  • 1,703
  • 4
  • 25
  • 45
  • There will be no other way than using an external library. You can't just append plain data in a Word document and expect that to be valid – Chris Feb 20 '12 at 23:00

1 Answers1

1

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.

Community
  • 1
  • 1
  • I am trying with iText but i am unable to use their JAR files. I am getting an error during importing. I created a library and added all the jars to that library. But I am getting an error saying package does not exist. what am i doing wrong? – ritratt Feb 21 '12 at 19:36