绑定完请刷新页面
取消
刷新

分享好友

×
取消 复制
6行代码!用Python将PDF转为word
2021-12-21 15:09:16

来源:机器学习算法与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=, 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=, end=None)
cv.close()

-------- End --------



分享好友

分享这个小栈给你的朋友们,一起进步吧。

Python编程时光
创建时间:2020-06-09 15:11:01
专注输出 Python 高质量原创文章
展开
订阅须知

• 所有用户可根据关注领域订阅专区或所有专区

• 付费订阅:虚拟交易,一经交易不退款;若特殊情况,可3日内客服咨询

• 专区发布评论属默认订阅所评论专区(除付费小栈外)

栈主、嘉宾

查看更多
  • highhand
    栈主

小栈成员

查看更多
  • 孔庆杰
  • Pantj
  • 高岩
  • www1392617710
戳我,来吐槽~