Count the number of pages in a pdf file

I have a problem when I use this code to count the number of pages in a pdf file:

if j[i].rstrip() == "Page" or j[i].rstrip() == "page":
            rxcountpages = re.compile(r"/Type\s*/Page([^s]|$)", re.MULTILINE|re.DOTALL)
            data = file("/home/suleiman/Desktop/CVE-2011-2462_36EE5F9C51316E060657AA86D48670E8","rb")

            print len(rxcountpages.findall(data))

mistake:

Traceback (last last call): File "pdf_scanner.py", line 89, in

main()

Pdf_scanner.py file, line 72, basically

print len(rxcountpages.findall(data))

TypeError: expected string or buffer

Can anyone help me with this?

-2
source share
1 answer

you need to read the contents of the file:

data = open("/home/suleiman/Desktop/CVE-2011-2462_36EE5F9C51316E060657AA86D48670E8","rb").read()
+1
source

Source: https://habr.com/ru/post/1612412/


All Articles