Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pypdf2 will not find text
#1
This code will not display any text and but wll print the number of pages, 31, in the pdf file. I can change the number of the page up and still no text printed.
Any suggestions?

# importing required modules
import PyPDF2
  
# creating a pdf file object
pdfFileObj = open('Documents/VisitDate.pdf', 'rb')
  
# creating a pdf reader object
pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
  
# printing number of pages in pdf file
print(pdfReader.numPages)
  
# creating a page object
pageObj = pdfReader.getPage(13)
  
# extracting text from page
print(pageObj.extractText())
  
# closing the pdf file object
Reply
#2
Works fine for me. Are you sure there is text on page 13? Remember that indexing starts at 0, not 1
Reply
#3
Strange. Does not matter what page I select - no text.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  PyPDF2 deprecation problem gowb0w 5 3,963 Sep-21-2023, 12:38 PM
Last Post: Pedroski55
  ModuleNotFoundError: No module named 'PyPDF2' Benitta2525 1 1,483 Aug-07-2023, 05:32 AM
Last Post: DPaul
  read a text file, find all integers, append to list oldtrafford 12 3,517 Aug-11-2022, 08:23 AM
Last Post: Pedroski55
  pyPDF2 PDFMerger close pensding file japo85 2 2,412 Jul-28-2022, 09:49 AM
Last Post: japo85
  find some word in text list file and a bit change to them RolanRoll 3 1,519 Jun-27-2022, 01:36 AM
Last Post: RolanRoll
  Find and delete above a certain line in text file cubangt 12 3,458 Mar-18-2022, 07:49 PM
Last Post: snippsat
  How to find tags using specific text (timestamps) in a url? q988988 1 1,371 Mar-08-2022, 08:09 AM
Last Post: buran
  labels.append(self.classes.index(member.find('name').text)) hobbyist 1 1,912 Dec-15-2021, 01:53 PM
Last Post: deanhystad
Thumbs Up [SOLVED] Find last occurence of pattern in text file? Winfried 4 4,382 Aug-13-2021, 08:21 PM
Last Post: Winfried
  PyPDF2 processing problem Pavel_47 6 9,747 May-04-2021, 06:58 AM
Last Post: chaitanya

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020