Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2021
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. # https://stackoverflow.com/questions/17098675/searching-text-in-a-pdf-using-python
  2. #
  3. # import packages
  4. import PyPDF2
  5. import re
  6.  
  7. # open the pdf file
  8. object = PyPDF2.PdfFileReader("test.pdf")
  9.  
  10. # get number of pages
  11. NumPages = object.getNumPages()
  12.  
  13. # define keyterms
  14. String = "Social"
  15.  
  16. # extract text and do the search
  17. for i in range(0, NumPages):
  18.     PageObj = object.getPage(i)
  19.     print("this is page " + str(i))
  20.     Text = PageObj.extractText()
  21.     # print(Text)
  22.     ResSearch = re.search(String, Text)
  23.     print(ResSearch)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement