从PDF页面的某些区域提取文本?

时间:2019-05-06 15:16:23

标签: python pdf pdfminer

我正在尝试解析PDF书籍,但是我只需要主体而没有页脚,页眉或脚注。

我浏览了pdfminer文档,但尚未成功。这是我用来获取文本的代码:

from pdfminer.converter import TextConverter
from pdfminer.pdfinterp import PDFPageInterpreter
from pdfminer.pdfinterp import PDFResourceManager
from pdfminer.pdfpage import PDFPage

with open(pdfname, 'rb') as fh:
    for page in PDFPage.get_pages(fh, caching=True, check_extractable=True):
        resource_manager = PDFResourceManager()
        fake_file_handle = io.StringIO()
        converter = TextConverter(resource_manager, fake_file_handle)
        page_interpreter = PDFPageInterpreter(resource_manager, converter)
        page_interpreter.process_page(page)
        text = fake_file_handle.getvalue()

0 个答案:

没有答案