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')
相关推荐
Jackilina_Stone42 分钟前
【论文|复现】YOLOFuse:面向多模态目标检测的双流融合框架
人工智能·python·目标检测·计算机视觉·融合
SEO-狼术1 小时前
Find Content Fast in PDF Documents
pdf
双叶8361 小时前
(Python)文件储存的认识,文件路径(文件储存基础教程)(Windows系统文件路径)(基础教程)
开发语言·windows·python
枫昕柚2 小时前
python
开发语言·python
木头左2 小时前
自动驾驶领域中的Python机器学习
python·机器学习·自动驾驶
Dxy12393102162 小时前
Python Requests-HTML库详解:从入门到实战
开发语言·python·html
seasonsyy2 小时前
2.安装CUDA详细步骤(含安装截图)
python·深度学习·环境配置·cuda
写点什么啦2 小时前
一键修复ipynb,Jupyter Notebook损坏文件
ide·python·jupyter
fishwheel2 小时前
Android:Reverse 实战 part 2 番外 IDA python
android·python·安全
测试19982 小时前
cmake应用:集成gtest进行单元测试
自动化测试·软件测试·python·测试工具·职场和发展·单元测试·测试用例