Hamed
Hamed

Reputation:

How do I use Apache POI to read a .DOC file in Java to separate images from text?

I need to read a Word .doc file from Java that has text and images. I need to recognize the images & text and separate them into 2 files.

I've recently heard about "Apache POI." How I can use Apache POI to read Word .doc files?

Upvotes: 5

Views: 24619

Answers (2)

banjollity
banjollity

Reputation: 4540

It's not free (or even cheap!) but Aspose.Words should be able to do this. Their evaluation download will let you play with small files.

Do the destination files also have to be Docs? You could open the docs in Office and save them out as HTML. Then the separation becomes trivial. RTF is also a viable option, but I can't recommend a good RTF parser off the top of my head.

Edit to say: I just remembered another possible solution: Jacob, but you'll need an instance of Office running on the same machine. It's short for Java COM Bridge and it lets you make calls to the COM libraries in Office to manipulate the documents. I'm sure it's not as scary as it might sound!

Upvotes: 1

Hi I am a troll
Hi I am a troll

Reputation:

The examples and sample code on apache's site are pretty good. I recommend you start there.

http://poi.apache.org/hwpf/quick-guide.html

To get specific bits of text, first create a org.apache.poi.hwpf.HWPFDocument. Fetch the range with getRange(), then get paragraphs from that. You can then get text and other properties.

Here for an example of extracting an image. Here for the latest revision as of this writing.

And of course, the Javadocs

Note that, according to the POI site,

HWPF is still in early development.

Upvotes: 13

Related Questions