在处理具有高分辨率图像和文本的某些文件时,PDFMiner.six会卡住,因此我想如果我能抑制布局分析,它可以跳过这些页面并继续执行。
from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter
from pdfminer.converter import TextConverter
from pdfminer.layout import LAParams
from pdfminer.pdfpage import PDFPage
from io import StringIO
abspath_pdf = r'C:\\Users\\shricharan.arumugam\\Desktop\\Baraka East_1 Ichron REPORT Final.pdf'
def convert_pdf_to_txt2(path):
rsrcmgr = PDFResourceManager()
retstr = StringIO()
codec = 'utf-8'
laparams = LAParams()
device = TextConverter(rsrcmgr, retstr, codec=codec, laparams=laparams)
fp = open(path, 'rb')
interpreter = PDFPageInterpreter(rsrcmgr, device)
password = ""
maxpages = 0
caching = True
pagenos=set()
i=1
#test_pages=PDFPage.get_pages(fp, pagenos, maxpages=maxpages, password=password,caching=caching, check_extractable=True)
for page in PDFPage.get_pages(fp, pagenos, maxpages=maxpages, password=password,caching=caching, check_extractable=True):
interpreter.process_page(page)
print(i)
i=i+1
text = retstr.getvalue()
fp.close()
device.close()
retstr.close()
return text
convert_pdf_to_txt2(abspath_pdf)
文档说要使用-n来禁止布局分析,但是有人能向我展示如何使用吗?