0

I have a legacy software which produces a xml and then with help of docx4j a docx document . I must also create a microsoft doc document from the xml file with java. How can I do that. I'd really appreciate for any help. Thanks

JasonPlutext
  • 15,352
  • 4
  • 44
  • 84
duracell
  • 644
  • 8
  • 13

2 Answers2

1

Look into poi. It's pretty much the defacto standard for modifying Microsoft documents with Java.

David
  • 19,577
  • 28
  • 108
  • 128
1

docx4j has POI as a dependency, and POI has reasonable support for the legacy binary doc format (hwpf). So you could use that to convert to doc without introducing additional dependencies. Basically, iterate through your content, and emit each paragraph/table/image in doc format. That would be the reverse of convert/in/Doc.java.

However, the devil is in the detail, and it would be a lot of work if your documents contain a variety of features. This assertion stands whether you were doing docx4j to binary doc (hwpf), or POI's own xwpf to hwpf, since POI doesn't have a common interface across the two of them.

So instead of using POI for this, I'd use JODConverter to drive LibreOffice (or OpenOffice, their docx features are a bit different) to convert docx to legacy binary .doc.

The JODConverter approach is definitely the path of least resistance, and will generally give good results. The downside with it is that if you find something which isn't supported properly, you'll have to wait for the LO/OO guys to fix it, which wouldn't be the case if you did decide to build binary doc output for docx4j using POI. If you did build this, we'd happily accept it as a contribution :-)

JasonPlutext
  • 15,352
  • 4
  • 44
  • 84