Articles Projects Tips Downloads Contacts About

DocxEditorKit library in JEditorPane/JTextPane.

The kit works with docx files. It can open docx file ad reflect the content in JEditorPane (or JTextPane). Also user can create styled content and store the content in docx format.

That's the first version which supports very basic functionality - text with attributes (font family, size, colors, effects), paragraph with attributes (align, indents, line spacing), simple images, simple tables.

In the furute I am going to extend the kit and include pagination, bullets/numberings, extended tables etc.

It uses dox4j library in background to read and write the files. The list of jars to be included in the classpath is below:

commons-codec-1.3.jar
commons-io-1.3.1.jar
commons-lang-2.4.jar
commons-logging-1.1.1.jar
docx4j-2.8.0.jar
jaxb-svg11-1.0.2.jar
jaxb-xmldsig-core-1.0.0.jar
jaxb-xslfo-1.0.1.jar
log4j-1.2.15.jar
poi-3.8.jar
poi-scratchpad-3.8.jar
xmlgraphics-commons-1.4.jar

The DocxEditorKit screenshot shows how it looks:

To show docx file in JEditorPane use following code:

        JEditorPane editorPane=new JEditorPane();
        editorPane.setEditorKit(new DocxEditorKit());
        editorPane.getEditorKit().read(new FileInputStream(pathToFile));

To save content back use

        editorPane.getEditorKit().write(new FileOutputStream(pathToFile));

The kit is free to use and anybody can see the sources and modify it as necessary.

Click here to get DocxEditorKit library. Here you can download the DocxEditorKit source code.

You can get here http://www.docx4java.org/docx4j/docx4j-2.8.1.zip all the docx4j libraries necessary for the kit.