社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

6行代码!用Python将PDF转为word

Python绿色通道 • 4 年前 • 628 次点击  

↑ 关注 + 星标 ,每天学Python新技能

后台回复【 大礼包】送你Python自学大礼包

pdf转word应该算是一个很常见的需求了
网上有些免费的转换工具,一方面不安全,有文件泄露风险,另一方面有免费转换的次数限制。
今天向大家分享一个很好用的工具:pdf2docx

安装

$ pip install pdf2docx

用法也很简单,核心方法是Converter
我写了一个小脚本,如有需要,大家可以直接copy走。

# -*- coding: utf-8 -*-
"""
Created on Sat Aug  7 16:36:59 2021

@author: LaoHu
"""

import argparse
from pdf2docx import Converter

def main(pdf_file,docx_file):
    cv = Converter(pdf_file)
    cv.convert(docx_file, start=0, end=None)
    cv.close()
    
if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--pdf_file",type=str)
    parser.add_argument('--docx_file',type=str)
    args = parser.parse_args()
    main(args.pdf_file,args.docx_file)

用法

python pdf2word.py --pdf_file  pdf文件路径\example.pdf --docx_file 输出word文件的路径\example.docx


不喜欢命令行跑脚本的同学可以copy下面简化版

from pdf2docx import Converter
pdf_file = 'pdf文件路径'
docx_file = '输出word文件的路径'
cv = Converter(pdf_file)
cv.convert(docx_file, start=0, end=None)
cv.close()




最近有一些小伙伴,让我帮忙找一些 面试题 资料,于是我翻遍了收藏的 5T 资料后,汇总整理出来,可以说是程序员面试必备!所有资料都整理到网盘了,欢迎下载!


点击👆卡片,关注后回复【面试题】即可获取



推荐阅读

  1. 好大的官威!!!某科技公司领导工作群里爆粗口,直接@员工滚

  2. 全球第一大社交APP翻车!被曝千人团队审查用户聊天记录

  3. 爷青回!AI把《灌篮高手》角色真人化,最帅的居然不是流川枫?



Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/120806