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()