简体   繁体   English

从 pdf 文件读取到文本没有结果

[英]Reading from pdf file to text yields no results

So I'm trying something very simple: I just want to read text from a pdf file in to a variable - that's it.所以我正在尝试一些非常简单的事情:我只想将 pdf 文件中的文本读入一个变量 - 就是这样。 This is what I'm getting:这就是我得到的:

在此处输入图像描述

Does anyone know a reliable way to just read pdf in to a text file?有谁知道将 pdf 读入文本文件的可靠方法?

Try the following library - pdfplumber:尝试以下库 - pdfplumber:

import pdfplumber
pdf_file = pdfplumber.open('anyfile.pdf')
page = pdf_file.pages[0]
text = page.extract_text()
print(text)
pdf_file.close()

I haven't used PyPDF2 before but pdfplumber seems to work well for me.我以前没有使用过 PyPDF2,但 pdfplumber 似乎很适合我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM