Python 提取加密的 PDF 中的文字

依赖

  • Python 库:fitz
shell 复制代码
$ python -m pip install fitz
  • 注:如果运行下述脚本过程中遇到 No module named 'frontend',可执行 python -m pip install frontend(要求 Python >=3.8)或 python -m pip install PyMuPDF

Python 脚本

python 复制代码
# extract_pdf_text.py
import fitz

def parsePDF(filePath):
    with fitz.open(filePath) as doc:
        text = ""
        for page in doc.pages():
            text += page.get_text()
        if text:
            return text

text = parsePDF(r'D:\downloads\intput.pdf')
with open('output.txt', mode='w', encoding='utf8') as f:
    f.write(text)

参考

相关推荐
m0_734949797 小时前
MySQL如何配置定时清理过期备份文件_find命令与保留周期策略
jvm·数据库·python
t***5447 小时前
Clang 编译器在 Orwell Dev-C++ 中的局限性
开发语言·c++
m0_514520578 小时前
MySQL索引优化后性能没提升_通过EXPLAIN查看索引命中率
jvm·数据库·python
H Journey8 小时前
Python 国内pip install 安装缓慢
python·pip·install 加速
oy_mail8 小时前
QoS质量配置
开发语言·智能路由器·php
oyzz1208 小时前
PHP操作redis
开发语言·redis·php
nashane8 小时前
HarmonyOS 6学习:网络能力变化监听与智能提示——告别流量偷跑,打造贴心网络感知应用
开发语言·php·harmony app
Polar__Star9 小时前
如何在 AWS Lambda 中正确使用临时凭证生成 S3 预签名 URL
jvm·数据库·python
凌波粒9 小时前
Java 8 “新”特性详解:Lambda、函数式接口、Stream、Optional 与方法引用
java·开发语言·idea
m0_743623929 小时前
React 自定义 Hook 的命名规范与调用规则详解
jvm·数据库·python