[Python] How extract text from PDF including images and text

Discussão em 'Python' iniciado por Stack, Abril 8, 2025.

  1. Stack

    Stack Membro Participativo

    I am going to extract text from multiple PDF files. The PDF files include text and some images and even some pages are scanned pages (I assumed the scanned pages are like images). I followed the below commands to extract text from PDF files.

    How can I edit my commands with a condition to check if each page contains any images, then extract text from images?

    lst_all_text = []

    for foldername,subfolders,files in os.walk(r"C:/MY PATH"):
    for file in files:
    # open the pdf file
    object = PyPDF2.PdfFileReader(os.path.join(foldername,file))
    # get number of pages
    NumPages = object.getNumPages()
    text = ""
    # extract text and do the search
    for i in range(0, NumPages):
    PageObj = object.getPage(i)
    text += PageObj.extractText()

    lst_all_text.append(text)

    Continue reading...

Compartilhe esta Página