convert_pdf2docx.py
# Import Libraries
from pdf2docx import parse
from typing import Tuple
def convert_pdf2docx(input_file: str, output_file: str, pages: Tuple = None):
"""Converts pdf to docx"""
if pages:
pages = [int(i) for i in list(pages) if i.isnumeric()]
result = parse(pdf_file=input_file,
docx_with_path=output_file, pages=pages)
summary = {
"File": input_file, "Pages": str(pages), "Output File": output_file
}
# Printing Summary
print("## Summary ########################################################")
print("\n".join("{}:{}".format(i, j) for i, j in summary.items()))
print("###################################################################")
return result
if __name__ == "__main__":
import sys
input_file = sys.argv[1]
output_file = sys.argv[2]
convert_pdf2docx(input_file, output_file)