我正在尝试解析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()