Here using csv module.
So here make header row with result under.
i haven't tried the first output but will let you know.
wondering if i can still ask few more questions here to refine the script?
also what i learn here is that i can make 1 line with opening file and open write in one line statement. this is what bugging me before.
So here make header row with result under.
import pdfplumber import csv pdf_file = "sample.pdf" search_word = 'end' header = ['search_word', 'page_nummer'] with pdfplumber.open(pdf_file) as pdf,open('result1.csv', 'w', newline='') as f_out: writer = csv.writer(f_out) pages = pdf.pages for page_nr, pg in enumerate(pages, 1): content = pg.extract_text() if search_word in content: writer.writerow(header) writer.writerow([search_word, page_nr])
Output:search_word,page_nummer
end,2
this is just awesome! this works, thank you so much snippsat!i haven't tried the first output but will let you know.
wondering if i can still ask few more questions here to refine the script?
also what i learn here is that i can make 1 line with opening file and open write in one line statement. this is what bugging me before.