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

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
展开阅读全文

页面更新:2024-06-20

标签:脚本   路径   次数   核心   常见   需求   风险   同学   代码   简单   文件   工具   方法   网上   科技

1 2 3 4 5

上滑加载更多 ↓
推荐阅读:
友情链接:
更多:

本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828  

© CopyRight 2020-2024 All Rights Reserved. Powered By 71396.com 闽ICP备11008920号-4
闽公网安备35020302034903号

Top