Welcome folks today in this blog post we will be using the pdf2docx
library to export the pdf document into microsoft word docx
file in python. All the full source code of the application is shown below.
Get Started
In order to get started you need to install the below library using the pip
command as shown below
pip install pdf2docx
And after that you need to create the app.py
file and copy paste the following code
app.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
import os from pdf2docx import Converter # Define the input and output file paths pdf_file_path = 'sample.pdf' docx_file_path = 'output.docx' # Create a PDF to DOCX converter object converter = Converter(pdf_file_path) # Convert PDF to DOCX converter.convert(docx_file_path) # Close the converter converter.close() # Check if the conversion was successful if os.path.exists(docx_file_path): print('Conversion completed!') else: print('Conversion failed!') |
Here you need to replace the paths
of the input pdf file and the output docx
file.