PDF to Word should be a very common demand for some free conversion tools on the Internet, on the one hand, it is not safe, there is a risk of document leakage, on the other hand, there are free conversion times limit. Today I want to share with you a very useful tool: PDf2docx

The installation

$ pip install pdf2docx
Copy the code

The usage is also very simple, the core method is to Converter I wrote a small script, if you need, you can directly 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)
Copy the code

usage

Python pdf2word.py --pdf_file PATH to the PDF file \example. PDF --docx_file Path to the word file \example.docxCopy the code

If you don’t like the command line running script, you can copy the simplified version below

From pdf2docx import Converter pdf_file = 'PDF file' docx_file = 'word file' CV = Converter(pdf_file) cv.convert(docx_file, start=0, end=None) cv.close()Copy the code