Is there a reasonable way to extract plain text from a Word file that doesn't depend on COM automation? (This is a a feature for a web app deployed on a non-Windows platform - that's non-negotiable in this case.)

Antiword seems like it might be a reasonable option, but it seems like it might be abandoned.

A Python solution would be ideal, but doesn't appear to be available.


I use catdoc or antiword for this, whatever gives the result that is the easiest to parse. I have embedded this in python functions, so it is easy to use from the parsing system (which is written in python).

import os

def doc_to_text_catdoc(filename):
    (fi, fo, fe) = os.popen3('catdoc -w "%s"' % filename)
    retval = fo.read()
    erroroutput = fe.read()
    if not erroroutput:
        return retval
        raise OSError("Executing the command caused an error: %s" % erroroutput)

# similar doc_to_text_antiword()

The -w switch to catdoc turns off line wrapping, BTW.


(Same answer as extracting text from MS word files in python)

Use the native Python docx module which I made this week. Here's how to extract all the text from a doc:

document = opendocx('Hello world.docx')

# This location is where most document content lives 
docbody = document.xpath('/w:document/w:body', namespaces=wordnamespaces)[0]

# Extract all text
print getdocumenttext(document)

See Python DocX site

100% Python, no COM, no .net, no Java, no parsing serialized XML with regexs, no crap.

  • Thank you very much for creating this library. I know you've posted this 3 years ago, but is there any way to sort of convert a DOCX document to HTML using your library? Cheers – Bo Milanovich Apr 20 '12 at 17:44
  • 1
    @mikemaccana can it parse .doc(not .docx) files also? – ofnowhere Jun 19 '14 at 14:33
  • 17
    If only there was a way to ask questions on StackOverflow. – mikemaccana Jun 19 '14 at 14:39

Using the OpenOffice API, and Python, and Andrew Pitonyak's excellent online macro book I managed to do this. Section 7.16.4 is the place to start.

One other tip to make it work without needing the screen at all is to use the Hidden property:

RO = PropertyValue('ReadOnly', 0, True, 0)
Hidden = PropertyValue('Hidden', 0, True, 0)
xDoc = desktop.loadComponentFromURL( docpath,"_blank", 0, (RO, Hidden,) )

Otherwise the document flicks up on the screen (probably on the webserver console) when you open it.


If all you want to do is extracting text from Word files (.docx), it's possible to do it only with Python. Like Guy Starbuck wrote it, you just need to unzip the file and then parse the XML. Inspired by python-docx, I have written a simple function to do this:

    from xml.etree.cElementTree import XML
except ImportError:
    from xml.etree.ElementTree import XML
import zipfile

Module that extract text from MS XML Word document (.docx).
(Inspired by python-docx <https://github.com/mikemaccana/python-docx>)

WORD_NAMESPACE = '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}'

def get_docx_text(path):
    Take the path of a docx file as argument, return the text in unicode.
    document = zipfile.ZipFile(path)
    xml_content = document.read('word/document.xml')
    tree = XML(xml_content)

    paragraphs = []
    for paragraph in tree.getiterator(PARA):
        texts = [node.text
                 for node in paragraph.getiterator(TEXT)
                 if node.text]
        if texts:

    return '\n\n'.join(paragraphs)
  • Great piece of code! A small remark about your blog, if the background of the code was not black, that would be more readable. – Jean-Francois T. Nov 24 '15 at 5:58
  • Oh, thanks for the comment. The problem is that I 'hacked' a bit the Github CSS so the colors match my site. But when Github make changes to their CSS, I have to patch my stylesheet again, like right now. Not sure I'll keep this approach... – Etienne Nov 24 '15 at 17:46
  • This works like a charm! – user5232465 Oct 17 '18 at 17:38

Open Office has an API


For docx files, check out the Python script docx2txt available at


for extracting the plain text from a docx document.



A Python port of the Apache Tika library, According to the documentation Apache tika supports text extraction from over 1500 file formats.

Note: It also works charmingly with pyinstaller

Install with pip :

pip install tika


#!/usr/bin/env python
from tika import parser
parsed = parser.from_file('/path/to/file')
print(parsed["metadata"]) #To get the meta data of the file
print(parsed["content"]) # To get the content of the file

Link to official GitHub

  • I tried your example and it seems it tries to download and start a Java .jar file: " Retrieving search.maven.org/remotecontent?filepath=org/apache/tika/…" <-- but then it fails with HTTP 403. – Prof. Falken Aug 21 '18 at 15:02
  • 1
    Follow these steps 1. You can manually download tika from here 2. Then open tika.py from \Lib\site-packages\tika folder and replace TikaJarPath = os.getenv('TIKA_PATH', "path\to\tika-server.jar\folder") TikaJarPath = os.getenv('TIKA_PATH', "F:\Projects\python\tika") – Dhinesh kumar M Aug 31 '18 at 13:03

This worked well for .doc and .odt.

It calls openoffice on the command line to convert your file to text, which you can then simply load into python.

(It seems to have other format options, though they are not apparenlty documented.)

  • openoffice and libreoffice are quite bad for deal with MS formats. – Tedo Vrbanec Mar 31 at 18:42

Your Answer

