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)

参考

相关推荐
染翰16 分钟前
lua入门以及在Redis中的应用
开发语言·redis·lua
王者鳜錸27 分钟前
PYTHON让繁琐的工作自动化-函数
开发语言·python·自动化
兔老大RabbitMQ1 小时前
git pull origin master失败
java·开发语言·git
tt5555555555551 小时前
C/C++嵌入式笔试核心考点精解
c语言·开发语言·c++
xiao助阵1 小时前
python实现梅尔频率倒谱系数(MFCC) 除了傅里叶变换和离散余弦变换
开发语言·python
科大饭桶2 小时前
C++入门自学Day14-- Stack和Queue的自实现(适配器)
c语言·开发语言·数据结构·c++·容器
扛麻袋的少年3 小时前
7.Kotlin的日期类
开发语言·微信·kotlin
麻辣清汤3 小时前
结合BI多维度异常分析(日期-> 商家/渠道->日期(商家/渠道))
数据库·python·sql·finebi
钢铁男儿3 小时前
Python 正则表达式(正则表达式和Python 语言)
python·mysql·正则表达式
钢铁男儿3 小时前
Python 正则表达式实战:解析系统登录与进程信息
开发语言·python·正则表达式