'Extracting bold text from Resumes( .Docx,.Doc,PDF) using Python

I have thousands of resumes in any format like word with .doc, .docx and pdf.

I want to extract bold text from these documents using textract library in python. is there a way to extract using textract?



Solution 1:[1]

An easy solution would be to use the python-docx package. install the package using ( !pip install python-docx )

You'll need to convert your pdf files to .docx . you can do that using any online pdf to docx converter or use python to do that.

the following lines of codes will extract all bold and italic contents of your resumes and save them in a dictionary called boltalic_Dict. you may retrieve either later on.

from docx import *

document = Document('path_to_your_files')
bolds=[]
italics=[]
for para in document.paragraphs:
    for run in para.runs:
        if run.italic :
            italics.append(run.text)
        if run.bold :
            bolds.append(run.text)

boltalic_Dict={'bold_phrases':bolds,
              'italic_phrases':italics}

Solution 2:[2]

Building on m.borhan's answer, since in their code some contiguous bold and italic portions failed to output as single item:

from docx import *

document = Document('path_to_your_files')
bolds=[]
italics=[]
last_bold = "" #last bold part
last_italic = "" #last italic part
for para in document.paragraphs:
    for run in para.runs:
        if run.italic :
            last_italic = last_italic + run.text
        elif run.bold :
            last_bold = last_bold + run.text
        else:
            italics.append(last_italic)
            bolds.append(last_bold)
            last_italic = ""
            last_bold = ""
italics = [i for i in italics if i]
bolds = [i for i in bolds if i]
boltalic_Dict={'bold_phrases':bolds,
              'italic_phrases':italics}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dharman
Solution 2 Recap_Hessian