What you describe is what my code dos in post #7
import pdfplumber pdf_file = "sample.pdf" search_word = 'text' with pdfplumber.open(pdf_file) as pdf: pages = pdf.pages for page_nr, pg in enumerate(pages, 1): content = pg.extract_text() if search_word in content: print(f'<{search_word}> found at page number <{page_nr}> '\ f'at index <{content.index(search_word)}>')
Output:<text> found at page number <1> at index <119>
<text> found at page number <2> at index <56>
So you can shuffle the the f-string
print() to get output you want.