简体   繁体   English

Python PDFMiner错误:“否/ Root对象! - 这真的是PDF吗?“

[英]Python PDFMiner error: “No /Root object! - Is this really a PDF?”

I am getting this error "No /Root object! - Is this really a PDF?" 我收到此错误“No / Root object! - 这真的是PDF吗?” using my MAC computer with Python 2.7 and PDFMiner version 20110515. The pdf files are not damaged because the same program with the same files works on my PC computer! 使用我的MAC计算机与Python 2.7和PDFMiner版本20110515.pdf文件没有损坏,因为相同的程序与我的PC计算机上的相同文件! Also I have tried many pdfs and this error exists for all of them. 此外,我尝试了很多pdf,并且所有这些都存在此错误。 Any ideas of what I should change in my MAC to not to get this error? 我应该在我的MAC中改变什么想法,以免得到这个错误?

I found the source of the problem: 我找到了问题的根源:

I had a method to read all the files in a directory and parse them. 我有一个方法来读取目录中的所有文件并解析它们。 Turns out that I had one hidden file in that directory that was not a pdf file! 原来我在该目录中有一个隐藏文件,而不是pdf文件!

Here is how I fixed the problem: 以下是我修复问题的方法:

for filename in os.listdir(INPUT_DIR_NAME):
    if filename.endswith('.pdf'):
        #do stuff!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM