开发者

Convert XPS to Word in Java

开发者 https://www.devze.com 2022-12-25 04:22 出处:网络
I want to convert XPS to W开发者_运维百科ord documents in Java. Can you help with the site or code to do this?Have you had a look at http://code.google.com/p/java-axp/ ?

I want to convert XPS to W开发者_运维百科ord documents in Java. Can you help with the site or code to do this?


Have you had a look at http://code.google.com/p/java-axp/ ?

That allows you to read the XPS.

The easiest file format to generate to create Word documents is RTF. You can use iText for that.


Another way to produce word files is through POI HWPF. Or if you can afford it, you might want to use Aspose.

Another option is to produce word files directly. If you can use Word 2007, or Word 2003 with the plugin, then I'd recommend the .docx format. It's basically XML, although you'll have to invest at least a day or two to understand the format.

Here's how I would recommend learning about word .docx format.

  1. Write a very small document (a couple of lines) in Word, and save it as test.docx
  2. Rename test.docx to test.zip
  3. Unzip test.zip and look at the files that are inside.
  4. Be amazed at the complexity, depth, and unfriendly names of the XML elements.
  5. Perservere to try to understand the relationships between paragraphs (P), paragraph properties (PPr), Text, Runs, etc.
  6. Refer to the documentation (33MB zipped) to understand the finer details.
  7. Start writing code to create files in this format. Look at openxml4j as a tool for doing the 'packaging' -- putting together all those files with the .rels etc. You can also look at the source for some of the examples.
  8. If you download all the xsd schemas, you could use tools like Sun's jaxb or Apache's Xmlbeans to make nice java classes for P, PPr, R, RPr, etc.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号