In PyPDF2 pdfreader.getNumPages()
gives me the total number of pages of a pdf file.
How can I get this using pdfminer?
Using pdfminer
,import
the necessary modules.
from pdfminer.pdfparser import PDFParser
from pdfminer.pdfdocument import PDFDocument
from pdfminer.pdfpage import PDFPage
Create a PDF parser object associated with the file object.
fp = open('your_file.pdf', 'rb')
parser = PDFParser(fp)
Create a PDF document object that stores the document structure.
document = PDFDocument(parser)
Iterate through the create_pages()
function incrementing each time there is a page.
num_pages = 0
for page in PDFPage.create_pages(document):
num_pages += 1
print(num_pages)