6 ms·
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?
by nickb 18y ago
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?
- aswanson 18y agoI know ruby has a method of extracting text from word docs through an api: http://rubyonwindows.blogspot.com/2007/06/automating-word-with-ruby-formatting.html http://rubyonwindows.blogspot.com/2007/06/automating-word-wi... I don't know about openxml though. [edit: Sorry, not portable to linux]
- pmorici 18y agoxlhtml 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.
- nickb 18y agoI'm hoping there's a way to automate it through OO.o... I'm pretty sure you can run it headless.
- etal 18y agoYes, or install python-uno for a nicer API: http://udk.openoffice.org/python/python-bridge.html http://udk.openoffice.org/python/python-bridge.html
- bootload 18y ago"... I'm hoping there's a way to automate it through OO.o. ..." Try http://search.cpan.org/dist/OpenOffice-OODoc/ http://search.cpan.org/dist/OpenOffice-OODoc/ and http://search.cpan.org/dist/OpenOffice-OODoc/OODoc/Intro.pod 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.
- iamelgringo 18y agoWould this work? http://www.artofsolving.com/opensource/pyodconverter http://www.artofsolving.com/opensource/pyodconverter
- iamelgringo 18y agoOr maybe you could hack somthing together with twill and this site: http://www.zamzar.com/conversionTypes.php http://www.zamzar.com/conversionTypes.php
- etal 18y agoNot 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/ 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.
- tsuraan 18y agoIf 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/ http://www.martiansoftware.com/nailgun/).