简体   繁体   中英

Having trouble getting all the page numbers from a pdf file to output

I'm having trouble getting all the page numbers from a pdf file. this is my code! I just get a one-page number that outputs I'm trying to get all the page numbers from my pdf file. How would I fix my code to get all the pdf page numbers? In total there are 20 pages.
enter image description here

My attempt looks something like this:

import PyPDF2
pdffileobj = open('test.pdf','rb')
pdfreader = PyPDF2.PdfFileReader(pdffileobj)
#extract the number of pages in the pdf and all text from the pdf

data = ''

#extract the text from the pdf
for i in range(pdfreader.numPages):
    pageobj = pdfreader.getPage(i)
    data += pageobj.extractText()

See https://pypdf2.readthedocs.io/en/latest/user/extract-text.html

from PyPDF2 import PdfReader

reader = PdfReader("example.pdf")
for page in reader.pages:
   print(page.extract_text())

print(f"pdf page count : {len(reader.pages)}")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM