我试图从我用PyPDF下载的PDF文件中获取文本。 这是我的代码:
if not PyPDF2.PdfFileReader('download.pdf').isEncrypted:
PyPDF2.PdfFileReader('download.pdf').getPage(0).extractText()
这是输出:
'\n\n˘ˇ˘ˆ˙\n˝˛˚˜!\n\n\n\n#\nˇ˘ˆ˙ˆ˝˛˝\n˙˙˘ ˘ˆ"˝\n$!%˙(˝)˙*˜+,˝-.#/.(#0)0)/.1.+02345.\n˛˛ˇ/#.$/0/70/#.+322.32˙˘˛˘˘\n˛˘ 8˙˘9:˘ˆ;\n˛˘\n\n˝=\n˙˘˛\n.ˇ<9:˘ˇˇ%˘˛ˇ ˘˘<˘\n˝>"?˝˘$@<˘*ˆˆ˘˙˘A˘B˘˙˘˛ˇ!˛˘˙˘˛ˇ˘\n1C˙ˆ˘06˛˘8+˛9:˘D10+E˝ˆ˘8\n$˘˘9:˘˘1C˙ˆ˘+˘F˛˘D$1+FE˝˘˛˘˘<˘?˝\n////)*˘1˘˛ ?GG˜*HI\nD˘˙A˘E\nJ$\n˛\nDLE///M˛˝˛˙˘˛˘˛\n˛˘˛>"?\n˙˘˛\n˛\n/)M6;˝˛˙˘˛˘\n˛\n///˛\n\n'
当我打开它的文件内容时。另外,当我使用另一个程序将pdf转换成txt时,效果很好。这是一个网页上的javascript呈现的pdf,不知道这是否有什么不同。在
以下内容摘自文档(https://pythonhosted.org/PyPDF2/PageObject.html)
因此,这个函数的性能似乎取决于pdf本身。
在win7,python3.6下,我遇到了PyPDF2没有正确编码一些PDF文件的问题。我的解决办法是六号乘客.
要从PDF中提取文本,可以使用类似于本文中的函数:https://stackoverflow.com/a/42154976/9524424
很适合我。。。
相关问题 更多 >
编程相关推荐