计算pdf文件中的页数 [英] count the number of pages in pdf file

查看:403
本文介绍了计算pdf文件中的页数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用此代码计算pdf文件中的页数时出现问题:

I have a problem when I use this code to count the number of pages in 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))

错误是:

回溯(最近通话最近):

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

main()

文件"pdf_scanner.py",第72行,位于主文件中

File "pdf_scanner.py", line 72, in main

print len(rxcountpages.findall(data))

TypeError:预期的字符串或缓冲区

TypeError: expected string or buffer

有人可以帮我吗?

推荐答案

您必须阅读文件内容:

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

这篇关于计算pdf文件中的页数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆