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)

参考

相关推荐
LabVIEW开发16 分钟前
LabVIEW + MATLAB 混合编程:爆炸场测试数据精准采集方案
开发语言·matlab·labview
嵌入式协会202407216 分钟前
(已解决)MinIO python 获取预签名出现forbidden、errornetwork等错误
java·开发语言·python
宸丶一24 分钟前
Day 14:任务追踪 - 让 Agent 拥有项目管理能力
开发语言·python
小短腿的代码世界32 分钟前
Qt行情协议解析与二进制编解码优化:从FIX到自定义协议的全链路架构
开发语言·qt·架构
skylar01 小时前
小白1分钟安装flash-attn
开发语言·python
JustNow_Man1 小时前
psmux快捷键
人工智能·python
默子昂1 小时前
ollama 自定义ui
开发语言·python·ui
abcy0712131 小时前
Python中使用FastAPI和HDFS进行异步文件上传
python·fastapi
abcy0712131 小时前
flask hdfs 异步上传图文教程csdn
python·flask
在放️1 小时前
Python 爬虫 · PyQuery 模块基础
爬虫·python