6行代碼!用Python將PDF轉(zhuǎn)為word
pdf轉(zhuǎn)word應(yīng)該算是一個(gè)很常見的需求了
網(wǎng)上有些免費(fèi)的轉(zhuǎn)換工具,一方面不安全,有文件泄露風(fēng)險(xiǎn),另一方面有免費(fèi)轉(zhuǎn)換的次數(shù)限制。
今天向大家分享一個(gè)很好用的工具:pdf2docx
安裝
$?pip?install?pdf2docx
用法也很簡單,核心方法是Converter
我寫了一個(gè)小腳本,如有需要,大家可以直接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
不喜歡命令行跑腳本的同學(xué)可以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()評(píng)論
圖片
表情
