Jan-10-2022, 02:13 AM
(Jan-08-2022, 10:09 AM)snippsat Wrote: pdfplumber may be a better tool for this and more updated,
it's been 5-6 year since PyPDF2 was updated and has stuff that is none pythonic like CamelCase🐫 usage everywhere.
So i can write a quick test for this task,using this sample pdf.
import pdfplumber pdf_file = "sample.pdf" search_word = 'end' 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:<end> found at page number <2> at index <349>
THIS Actually Works!!! awesome thank you so much. genius. can i use this?
still hoping if i can fix the original code though.