python办公自动化(5)识别PDF文件中文字
pdfminer官网说明:由于PDF文件具有如此大而复杂的结构,因此将PDF文件解析为一个整体会浪费时间和内存。但是,并非大多数PDF处理任务都需要每个部分。因此,PDFMiner采取了一种惰性分析策略,即仅在必要时才对内容进行解析。要解析PDF文件,您至少需要使用两个类:PDFParser和PDFDocument。这两个对象相互关联。 PDFParser从文件中获取数据并PDFDocument存储。您还需要 PDFPageInterpreter处理页面内容并将PDFDevice其转换为所需的内容。 PDFResourceManager用于存储共享资源,例如字体或图像
from pdfminer.pdfparser import PDFParser
from pdfminer.pdfdocument import PDFDocument
from pdfminer.pdfpage import PDFPage
from pdfminer.layout import LTTextBoxHorizontal, LAParams
from pdfminer.pdfinterp import PDFResourceManager,PDFPageInterpreter
from pdfminer.converter import PDFPageAggregator
def parase_pdf2text(pdf_path,pasword,text_path):
# Create a PDF parser object associated with the file object.
parser = PDFParser(open(pdf_path, 'rb'))
# Create a PDF do