Skip to content

Latest commit

 

History

History
51 lines (40 loc) · 1.41 KB

README.md

File metadata and controls

51 lines (40 loc) · 1.41 KB

A pure Java library for converting Microsoft Word (docx) files to Java2D.

Quick Start

Create a DocxReader and render it to your GraphicsBuilder implementation:

Renderer renderer = new DocxRenderer(new File("input.docx"));

renderer.render(new GraphicsBuilder() {
	@Override
	public Graphics2D nextPage(int pageWidth, int pageHeight) {
		BufferedImage bi = new BufferedImage(pageWidth, pageHeight, BufferedImage.TYPE_INT_RGB);

		return (Graphics2D) bi.getGraphics();
	}
});

Note: A real GraphicsBuilder implementation (see examples below) will need to keep a reference to the Graphics2D object for displaying to a screen, saving to disk, etc

Examples

Maven Dependency

<dependency>
	<groupId>com.github.jamescarter.ooxml2java2d</groupId>
	<artifactId>docx2java2d</artifactId>
	<version>1.1.0</version>
</dependency>

FAQ

Why is the output so huge?

The output is in OOXML's native units (twips). The size can be reduced by setting the scale of the Graphics2D object:

public class ScaledGraphicsBuilder implements GraphicsBuilder {
	@Override
	public Graphics2D nextPage(int pageWidth, int pageHeight) {
		Graphics2D g2 = ...;
		g2.scale(0.05, 0.05); // native twips to actual size (72 DPI)
		return g2;t
	}
}