Python 3 Script to Convert Word DOCX to PDF Document Using pdf2docx Library Full Project For Beginners

Python 3 Script to Convert Word DOCX to PDF Document Using pdf2docx Library Full Project For Beginners

 

Welcome folks today in this blog post we will be converting docx to pdf using pdf2docx library 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 following library by using the pip command

 

pip install docx2pdf

 

After installing this library you need to create an app.py file and copy paste the following code

 

app.py

 

# Python3 program to convert docx to pdf 
# using docx2pdf module 

# Import the convert method from the 
# docx2pdf module 
from docx2pdf import convert 

# Converting docx present in the same folder 
# as the python file 
convert("sample1.docx")

 

 

This will convert the single docx file to pdf document using the docx2pdf library.

 

In order to provide a custom output file name for your pdf file you can use the below snippet of code

READ  Python Tkinter Random Number Generator Using Random Library GUI Desktop App Full Project For Beginners

 

 

# Import the convert method from the 
# docx2pdf module 
from docx2pdf import convert 
  
# Converting docx specifying both the input  
# and output paths 
convert("GeeksForGeeks\GFG_1.docx", "Other_Folder\Mine.pdf")

 

 

And now we will look at how we can convert bulk docx files to pdf documents with the below snippet of code

 

 

# Python3 program to convert docx to pdf 
# using docx2pdf module 
  
# Import the convert method from the 
# docx2pdf module 
from docx2pdf import convert 
  
# Bulk Conversion 
convert("uploads")

 

 

And now it will convert all the files which are present inside the uploads directory and it will create a output directory containing all the pdf files

Leave a Reply