0

I am using HWPFDocument to modify some doc file. However, when I try to save a new doc file with anchor image, the image will become broken. Does any method that can handle this case? Here are some my codes.

File file = new File("testdoc.doc");
FileInputStream fis = new FileInputStream(file);
POIFSFileSystem poifs = new POIFSFileSystem(fis);
HWPFDocument doc = new HWPFDocument(poifs);

FileOutputStream out = new FileOutputStream("testtt.doc");
doc.write(out);
out.close();
doc.close();

I do not modify anything of the doc file but the anchor image still become broken.

KC L
  • 79
  • 1
  • 6
  • 1
    Why not upgrade your apache poi library and use **XWPFDocument** with a **.docx** file ? – Frank Oct 12 '17 at 08:25
  • @Frank I know XWPFDocument can handle this case with docx file, but I need to handle some doc file right now :( – KC L Oct 12 '17 at 08:30
  • 1
    I don't know if you will be able to do it . From [Documentation](https://poi.apache.org/document/) - **At the moment we unfortunately do not have someone taking care for HWPF and fostering its development. What we need is someone to stand up, take this thing under his hood as his baby and push it forward. Ryan Ackley, who put a lot of effort into HWPF, is no longer on board, so HWPF is an orphan child waiting to be adopted.** – Frank Oct 12 '17 at 08:33
  • So it is a bug that do not fixed? – KC L Oct 12 '17 at 08:35
  • It's not a bug , someone started to develop and at one moment they stopped to develop features . So in may cases you can get problems using it . – Frank Oct 12 '17 at 08:37
  • Okay, then I may try some alternatives to continue my work. Anyway, thanks for answering. – KC L Oct 12 '17 at 08:39
  • @KCL Frank's comment is right. I was developing a custom HWPF version for one of my clients some years ago and know what is missing. I assume that although things have improved in the public version, it still cannot handle many non-trivial aspects of a doc file, especially when writing a doc file and even more so when content has been added. – Rainer Schwarze Oct 13 '17 at 12:07

0 Answers0