我使用PyPDF2和ipywidgets创建一个用户界面,让用户上传pdf文件并从中读取文本。问题是PyPDF2正在将页脚和页眉捕获到文本中。用户可以上传任何文件,因此删除这些文件的过程必须是自动化的,可以用于任何文件。是否有任何方法可以使用PyPDF2实现这一点
谢谢
代码:
def content_getter():
#Reads from the ipywidget
file = io.BytesIO(ui.children[0].children[1].data[0])
pdfReader = PyPDF2.PdfFileReader(file)
numPages = pdfReader.getNumPages()
allLines = []
for pageno in range(numPages):
pdfReader = PyPDF2.PdfFileReader(file)
pageObj = pdfReader.getPage(pageno)
text = pageObj.extractText()
li = text.splitlines()
allLines = allLines + li
final_output = ''.join(allLines)
return final_output,allLines
目前没有回答
相关问题 更多 >
编程相关推荐