[英]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.我无法从 pdf 文件中获取所有页码。 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.
我只得到一个输出的一页码,我试图从我的 pdf 文件中获取所有页码。 How would I fix my code to get all the pdf page numbers?
我将如何修复我的代码以获取所有 pdf 页码? In total there are 20 pages.
总共有20页。
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见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)}")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.