The error message suggests that the method reader.numPages is deprecated and has been removed in PyPDF2 version 3.0.0. Instead, you should use len(reader.pages) to get the number of pages in the PDF document. Here's an example:

import PyPDF2

# Open the PDF file
with open('example.pdf', 'rb') as file:
    # Create a PDF reader object
    reader = PyPDF2.PdfFileReader(file)
    
    # Get the number of pages using len(reader.pages)
    num_pages = len(reader.pages)
    
    # Print the number of pages
    print(f'Total pages: {num_pages}')

By using len(reader.pages), you can retrieve the number of pages in the PDF document without encountering the DeprecationError.

PyPDF2errorsDeprecationError readernumPages is deprecated and was removed in PyPDF2 300 Use lenreaderpages instead

原文地址: https://www.cveoy.top/t/topic/i49T 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录