Welcome folks today in this blog post we will be converting bulk word (.docx) to pdf
documents in command line using docx2pdf
library using 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 docx2pdf
Usage
Now after installing this library you can use the docx2pdf
command to convert the docx
to pdf
documents in the terminal as shown below
docx2pdf sample.docx sample.pdf
This above command will convert the sample.docx
file to sample.pdf
Providing Custom Path
You can even provide custom
path inside the command as well
docx2pdf uploads/sample.docx uploads/sample.pdf
As you can see we are converting the file stored in uploads
folder
Bulk Conversion in Directory
You can even convert all the files present inside a certain directory
to bulk convert as shown below
docx2pdf ##directoryname##
docx2pdf uploads
This will convert all the docx
files present inside the uploads
folder to pdf
documents
Usage
1 2 3 4 5 6 7 8 9 10 11 |
from docx2pdf import convert convert("demo.docx") # Converting docx specifying both the input # and output paths convert("uploads/demo.docx", "uploads/demo.pdf") #directory storing all the files bulk convert convert("uploads") |
As you can see we are importing the docx2pdf
module at the very top and then we are using the convert()
method to carry out the conversion of docx to pdf
files
Now if you execute the python
script then you will see the conversion
process at the command line
python app.py