可以使用 Python 的 PyPDF2 库来读取 PDF 文件。安装方法:
pipinstall pypdf2
然后,可以使用以下代码来读取 PDF 文件并将其转换为文本:
import PyPDF2# 打开 PDF 文件
with open('example.pdf', 'rb') as file:
# 创建 PDF 读取器
reader = PyPDF2.PdfFileReader(file)
# 读取 PDF 的第一页
page = reader.getPage(0)
# 将第一页转换为文本
t