Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 768
Saurav Saha Avatar asked Sep 02 '25 15:09

Saurav Saha


1 Answers

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
like image 71
Karmveer Singh Avatar answered Sep 05 '25 16:09

Karmveer Singh