Python实用工具:pdf转doc

该工具只能使用在英文目录下,且无法转换出图片,以及文本特殊格式。

下载依赖项

bash 复制代码
pip install PyPDF2

升级依赖项

bash 复制代码
pip install PyPDF2 --upgrade

查看库版本

bash 复制代码
python -c "import PyPDF2; print(PyPDF2.__version__)"

下载第二个依赖项

bash 复制代码
pip install python-docx

给权限

bash 复制代码
pip install python-docx --user

验证

bash 复制代码
python -c "from docx import Document; print('python-docx 安装成功')"
python 复制代码
# -*- coding: utf-8 -*-
# pdf_to_word_pypdf2_python_docx.py
import PyPDF2
from docx import Document

def pdf_to_word_pypdf2_python_docx(pdf_path, word_path):
    with open(pdf_path, 'rb') as pdf_file:
        pdf_reader = PyPDF2.PdfReader(pdf_file)  # 更新为PdfReader
        document = Document()

        for page in pdf_reader.pages:  # 使用pages属性直接遍历
            text = page.extract_text()  # 更新方法名为extract_text()
            document.add_paragraph(text)

        document.save(word_path)

# 使用示例
pdf_to_word_pypdf2_python_docx('123456.pdf', 'output.docx')
相关推荐
宸汐Fish_Heart16 分钟前
Python打卡训练营Day22
开发语言·python
伊织code43 分钟前
PyTorch API 9 - masked, nested, 稀疏, 存储
pytorch·python·ai·api·-·9·masked
wxl7812271 小时前
基于flask+pandas+csv的报表实现
python·flask·pandas
鸡鸭扣2 小时前
DRF/Django+Vue项目线上部署:腾讯云+Centos7.6(github的SSH认证)
前端·vue.js·python·django·腾讯云·drf
钢铁男儿2 小时前
Python中的标识、相等性与别名:深入理解对象引用机制
java·网络·python
且慢.5892 小时前
Python_day22
python·机器学习
虚空之月&&轮舞者2 小时前
Python与矢量网络分析仪3671E:通道插损自动化校准(Vscode)
网络·python·自动化
西红柿土豆丶2 小时前
基于Flask、Bootstrap及深度学习的水库智能监测分析平台
人工智能·python·深度学习·flask·bootstrap
老胖闲聊2 小时前
Python httpx库终极指南
开发语言·python·httpx
萧霍之3 小时前
基于onnxruntime结合PyQt快速搭建视觉原型Demo
pytorch·python·yolo·计算机视觉