Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
PDFMiner: Python PDF text parser (unixuser.org)
41 points by iamelgringo on July 27, 2008 | hide | past | favorite | 13 comments


Does anyone know of a good way of converting MS OpenXML (docx, pptx etc) and old Word (doc, ppt etc) files to txt through command line Linux?


I know ruby has a method of extracting text from word docs through an api: http://rubyonwindows.blogspot.com/2007/06/automating-word-wi...

I don't know about openxml though.

[edit: Sorry, not portable to linux]


Yeah, I think you also need a Word license for this to work.


If you do I didn't use one. My trial liscense ran out a long time ago but the scripts still work.


Not sure about standalone OOXML converters, but there's a widely ported command-line utility called antiword for converting .doc format to text:

http://www.winfield.demon.nl/

OO.o 3.0 is supposed to have OOXML import included (it's a separate extension in 2.x), so using the UNO bindings or possibly some command-line flags, OpenOffice.org may be able to do some justice to .docx.

But if all you want is the text from an OOXML file, formatting be damned, it's actually straightforward to code (just like ODF):

1. Unzip the file to get its component XML files

2. Read content.xml (or whatever the OOXML equivalent is)

3. Parse the XML and extract the text content of every node (e.g. make a list of the strings).

4. Spit that back out, search it, etc.


xlhtml will work for .xls files. I'm not aware of one utility that will read out the text reliably from all MS formats though. I've been pondering this same problem as of late and have been thinking about a virtual machine approach.

have a conversion "service" running in a Windows VM that has the latest office installed. Use something like Python with the pywin32 module to extract text via COM.

Advantage there is you don't have to worry about your thing breaking with new releases of Office, you just upgrade to the latest version.

Disadvantage obviously, the overhead of the VM cost of a windows and office license and need to role back the vm snapshot from time to time if you get any viruses.


I'm hoping there's a way to automate it through OO.o... I'm pretty sure you can run it headless.


"... I'm hoping there's a way to automate it through OO.o. ..."

Try http://search.cpan.org/dist/OpenOffice-OODoc/ and http://search.cpan.org/dist/OpenOffice-OODoc/OODoc/Intro.pod I've had some success parsing Open Office docs & word docs to text. Be prepared to parse XML and read the spec.


Yes, or install python-uno for a nicer API:

http://udk.openoffice.org/python/python-bridge.html


Or maybe you could hack somthing together with twill and this site: http://www.zamzar.com/conversionTypes.php



If you look at apache POI, they have libraries for handling doc, ppt, xls, etc. There's also a poi-like toolkit for handling the new docx, pptx, etc file formats somewhere, but I forgot where. They're java libraries, but it's pretty easy to write some simple stand-alone conversion tools using them. If you need to convert a ton of files at a time and the JVM startup is killing you, you can try nailgun (http://www.martiansoftware.com/nailgun/).


Been looking for something like this for a while now. Thanks. Wonder if there is a Ruby effort underway.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: