python-3.x - 如何在 Python3 脚本中使用 PyPDF2 从 PDF 中读取阿拉伯文本
问题描述
我正在尝试编写一个从 PDF 中提取阿拉伯文本的脚本。
我尝试了不同的编码,例如 utf-8、utf-16 和 cp1256,但到目前为止没有运气。
我的代码是:
import PyPDF2, codecs
pdf_file = open('okt2020.pdf', 'rb')
reader = PyPDF2.PdfFileReader(pdf_file)
print(reader.numPages)
page = reader.getPage(0)
text = page.extractText()
pdf_file.close()
with open('win1256.txt','w',encoding='cp1256') as e:
e.write(text)
with open('unicode.txt','w',encoding='utf-8-sig') as f:
f.write(text)
以上两个输出文件都有奇怪的字符,例如:
!"#$%&#'(
)*+,-+./
001%"#234
5467879!#':;;9<79
=8>>?9
!#'73>9<79
!%6(7879
@AB/ACD*E
FGFGHIJ*E
K+HL*E
H,M*E
N+HO*E
NHOD*E
HJP
Q!"#$%&'(&%)'&*!('*+!,'(&!,'-)!*./01234
有人可以指出我在这里做错了什么吗?
提前致谢!
解决方案
推荐阅读
- dart - 如何在 Flutter 中使用 SQFlite 更新数据库表
- gcc - gdb中“非调试符号:”中变量中的点是什么
- python - 如何附加不同的时间戳数据帧?
- javascript - IIFE 用于避免名称冲突?
- cluster-analysis - 数据缩减/转换
- mysql - 如何从三个表中计数?
- html - 无法在谷歌地图右上角定位按钮
- unity3d - Unity 依赖注入 - DependencyResolver.current.GetService() 为 Web API 返回 null
- neo4j - Neo4j Cypher - 分别并按顺序获取多条路径上的节点
- vb.net - 外部程序退出后出现“调用线程必须是STA,因为许多UI组件需要这个”错误