Python 如何在使用PDFminer将多页PDF提取为文本时删除页眉和页脚?

Python 如何在使用PDFminer将多页PDF提取为文本时删除页眉和页脚?,python,header,footer,text-extraction,pdfminer,Python,Header,Footer,Text Extraction,Pdfminer,我已经使用Python中的PDFminer.six成功地从多页PDF中提取了文本,并将其转换为单个字符串,但我希望在将PDF提取为文本时删除每个页面的页眉和页脚 到目前为止,类似的问题还没有给我答案。是否有删除或提取页眉和页脚的特定功能?我想删除每页的前7行和后7行也可以 希望有人能帮我 def pdf_to_text(pdfname): # PDFMiner boilerplate rsrcmgr = PDFResourceManager() sio = StringIO() device =

我已经使用Python中的PDFminer.six成功地从多页PDF中提取了文本,并将其转换为单个字符串,但我希望在将PDF提取为文本时删除每个页面的页眉和页脚

到目前为止,类似的问题还没有给我答案。是否有删除或提取页眉和页脚的特定功能?我想删除每页的前7行和后7行也可以

希望有人能帮我

def pdf_to_text(pdfname):
# PDFMiner boilerplate
rsrcmgr = PDFResourceManager()
sio = StringIO()
device = TextConverter(rsrcmgr, sio, codec='utf-8', laparams=LAParams(char_margin = 20))
interpreter = PDFPageInterpreter(rsrcmgr, device)

# get text from file
fp = open(pdfname, 'rb')
for page in PDFPage.get_pages(fp):
    interpreter.process_page(page)
fp.close()
# Get text from StringIO
text = sio.getvalue()

# close objects
device.close()
sio.close()

return text