失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > 已解决AttributeError: ‘Document‘ object has no attribute ‘convertToPDF‘

已解决AttributeError: ‘Document‘ object has no attribute ‘convertToPDF‘

时间:2019-11-24 02:27:28

相关推荐

已解决AttributeError: ‘Document‘ object has no attribute ‘convertToPDF‘

已解决AttributeError: ‘Document‘ object has no attribute ‘convertToPDF‘

文章目录

报错代码报错翻译报错原因解决方法帮忙解决

报错代码

粉丝群一个小伙伴想用python读取PDF,但是发生了报错(当时他心里瞬间凉了一大截,跑来找我求助,然后顺利帮助他解决了,顺便记录一下希望可以帮助到更多遇到这个bug不会解决的小伙伴),报错代码如下:

import globimport fitzdoc = fitz.open()for img in sorted(glob.glob(r"C:\Users\Administrator\Desktop\1.png")):imgdoc = fitz.open(img)pdfbytes = imgdoc.convertToPDF()imgpdf = fitz.open("pdf", pdfbytes)doc.insertPDF(imgpdf)doc.save('dip_ch02.pdf')doc.close()

可以看到导包没有问题,但是代码有高亮:

运行后报错信息截图如下所示

AttributeError: ‘Document‘ object has no attribute ‘convertToPDF‘

报错翻译

报错信息翻译如下

属性错误:“Document”对象没有属性“convertToPDF”

报错原因

报错原因:

convertToPDF方法需要安装依赖模块,而粉丝没安装所以报错了,小伙伴们按下面的方法安装即可!!!

解决方法

执行下面pip安装命令即可:

pip install PyMuPDF

安装后可以看到高亮消失了:

帮忙解决

本文已收录于:《告别Bug》专栏

本专栏用于记录学习和工作中遇到的各种疑难Bug问题,以及粉丝群里小伙伴提出的各种问题,文章形式:报错代码 + 报错翻译 + 报错原因 + 解决方法,包括程序安装、运行程序过程中等等问题,订阅专栏+关注博主后如遇到其他问题可私聊帮忙解决!!!

如果觉得《已解决AttributeError: ‘Document‘ object has no attribute ‘convertToPDF‘》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。