【发布时间】:2019-01-17 20:48:47
【问题描述】:
我需要从 pdf 中提取文本。但是pdf有一些粗体和下划线的文本。我尝试了 MyPDF2,但在尝试阅读那些包含格式化文本的 pdf 时出错。
import PyPDF2
pdf_file = open('Downloads/th.pdf','rb')
read_pdf = PyPDF2.PdfFileReader(pdf_file)
number_of_pages = read_pdf.getNumPages()
page = read_pdf.getPage(0)
page_content = page.extractText()
print (page_content)
输出
˘ˇˆˆ˝˛˚˜ ˜˚!˘˘ˇˆ˙˛˝˚˜˚ !ˆ"#$ˆ%&'˛"˝#$%˝˚'(˚˛)˛˝*+!-.$ˆ˚˛˚˛˘/˛˛0˛122/
˘˛˘˚˘˚2ˆ$".#$ˆ%˘˛˛$ˆ$%#$ˆ%˛˛˛˛˝˝(0/ 0$%˙˚˙3#"$˘--4˛0˚!
ˆ"#$ˆ%56272˛ˇ5'˛6222˛'4˘8(9˛(˜˚˛&˙˙˙˙˙
【问题讨论】:
-
你尝试了什么?你可以发布代码吗?错误是什么?你真的是说MyPDF2吗?我之前在 Python 中使用过 PyPDF2……
-
我不知道带下划线的文本,但关于 bold 字体,试试这个更新的答案stackoverflow.com/questions/53398611/…,它是免费软件 R.
标签: python stanford-nlp