Python 旧代码没有';t使用新版本的PDFMiner

Python 旧代码没有';t使用新版本的PDFMiner,python,pdfminer,Python,Pdfminer,我“继承”了前学院的一个项目。这个程序在早些时候运行得很好,但对我来说不起作用。原因是collegue使用的是PDFMiner的旧版本(我不知道是哪个版本),而我使用的是新版本。代码如下: filpath=r"...." rsrcmgr = PDFResourceManager() retstr = StringIO() laparams = LAParams() device = PDFPageAggregator(rsrcmgr, laparams=laparams) fp = open(f

我“继承”了前学院的一个项目。这个程序在早些时候运行得很好,但对我来说不起作用。原因是collegue使用的是PDFMiner的旧版本(我不知道是哪个版本),而我使用的是新版本。代码如下:

filpath=r"...."
rsrcmgr = PDFResourceManager()
retstr = StringIO()
laparams = LAParams()
device = PDFPageAggregator(rsrcmgr, laparams=laparams)
fp = open(filepath,'rb')
interpreter = PDFPageInterpreter(rsrcmgr,device)
parser = PDFParser(fp)
doc = PDFDocument()
parser.set_document(doc)
doc.set_parser(parser)
doc.initialize('') 
起初我犯了错误

doc = PDFDocument()
TypeError: __init__() missing 1 required positional argument: 'parser'. 
我将行doc=PDFDocument()更改为doc=PDFDocument(解析器)。这是有效的,但现在我有了错误

'PDFDocument' object has no attribute 'set_parser'
它显然来自doc.set\u parser(解析器)行。 我现在该怎么办

附加信息:旧程序中的导入行为

from pdfminer.pdfparser import PDFParser, PDFDocument
现在不行了,我不得不改成两行

from pdfminer.pdfparser import PDFParser
from pdfminer.pdfdocument import PDFDocument
提前谢谢

更新。 我最终以一种“便宜”的方式解决了我的问题——我安装了pdfminer的旧版本,所以我不需要更改代码中的任何内容

你看过那部电影了吗


从链接中逐字复制。

谢谢!我编辑了我的问题,因为我更进一步了。现在我不明白如何使用doc.set\u解析器(parser)。在文档中,我看到set_解析器是在2013年被删除的,这很奇怪,因为collegue在2018年编写了这个程序,并且正如我所说的那样,当时它可以正常工作。我不再能够使用pdfminer访问机器,但如果您提供python、pdfminer、,也许还有你的操作系统。如果有人遇到你的问题,想要找到类似问题的答案,那么向他们发布你是如何解决问题的,这会很有帮助。
from pdfminer.pdfparser import PDFParser
from pdfminer.pdfdocument import PDFDocument
from pdfminer.pdfpage import PDFPage
from pdfminer.pdfpage import PDFTextExtractionNotAllowed
from pdfminer.pdfinterp import PDFResourceManager
from pdfminer.pdfinterp import PDFPageInterpreter
from pdfminer.pdfdevice import PDFDevice

# Open a PDF file.
fp = open('mypdf.pdf', 'rb')
# Create a PDF parser object associated with the file object.
parser = PDFParser(fp)
# Create a PDF document object that stores the document structure.
# Supply the password for initialization.
document = PDFDocument(parser, password)
# Check if the document allows text extraction. If not, abort.
if not document.is_extractable:
    raise PDFTextExtractionNotAllowed
# Create a PDF resource manager object that stores shared resources.
rsrcmgr = PDFResourceManager()
# Create a PDF device object.
device = PDFDevice(rsrcmgr)
# Create a PDF interpreter object.
interpreter = PDFPageInterpreter(rsrcmgr, device)
# Process each page contained in the document.
for page in PDFPage.create_pages(document):
    interpreter.process_page(page)