Search code examples
pythonpython-3.xfontsdocxpython-docx

Retrieving font style, size and other attributes from a word document


I am working with python 3.6, my question is that is it possible to retrieve information from an existing document such as the font name of the text, the font size,etc.

I have tried using python-docx to help me with it but when I try using run.font I only get None returned.


Solution

  • I think this is helpful.

    import docx
    path = '/home/karamveer/Downloads/222.docx' #your docx file path
    doc = docx.Document(path)
    for p in doc.paragraphs:
        name = p.style.font.name
        size = p.style.font.size
        print name, size