How can I get the total count of total pages of a pdf using pdfminer in python

后端 未结 4 473
旧巷少年郎
旧巷少年郎 2021-02-06 17:10

In PyPDF2 pdfreader.getNumPages() gives me the total number of pages of a pdf file.

How can I get this using pdfminer?

4条回答
  •  深忆病人
    2021-02-06 17:42

    I found pdfminer very slow in getting total number of pages. Found this a cleaner and faster solution:

    pip3 install PyPDF2

    from PyPDF2 import PdfFileReader
    def get_pdf_page_count(path):
      with open(path, 'rb') as fl:
        reader = PdfFileReader(fl)
        return reader.getNumPages()
    

提交回复
热议问题