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)

参考

相关推荐
xxie12379410 分钟前
Python 闭包:函数嵌套的 “状态捕获” 机制
开发语言·python
骑士雄师13 分钟前
java面试记录: sychonized 锁,熔断组件,分布式锁
java·开发语言·面试
c_lb728830 分钟前
最新AI量化提效,交易认知和技术实现要接上
人工智能·python
机汇五金_31 分钟前
钣金外壳定制厂家助力设备升级
大数据·人工智能·python·物联网
lilihuigz1 小时前
Meta Box完整指南:WordPress自定义字段与内容框架高效构建结构化内容 - 易服客工作室
java·开发语言
xxie1237941 小时前
Python 闭包的调用方法与实践
开发语言·python
HZZD_HZZD1 小时前
用电行为异常检测VAE-基于PyTorch设计用电行为异常检测模型:从时序特征提取到变分自编码器部署的完整实战
人工智能·pytorch·python
aini_lovee1 小时前
计算 HOG算子的典型 MATLAB 程序
开发语言·matlab
楷哥爱开发1 小时前
降低网络爬虫成本:基础设施优化指南
服务器·开发语言·php
思-无-涯1 小时前
AI Agent技能编写与质量保障
人工智能·python