search for a word in pdf using python

Solutions on MaxInterview for search for a word in pdf using python by the best coders in the world

showing results for - "search for a word in pdf using python"
Yasmine
08 Jan 2020
1import PyPDF2
2import re
3
4# Open the pdf file
5object = PyPDF2.PdfFileReader(r"C:\TEST.pdf")
6
7# Get number of pages
8NumPages = object.getNumPages()
9
10# Enter code here
11String = "Enter_the_text_to_Search_here"
12
13# Extract text and do the search
14for i in range(0, NumPages):
15    PageObj = object.getPage(i)
16    Text = PageObj.extractText()
17    if re.search(String,Text):
18         print("Pattern Found on Page: " + str(i))
19