Are you looking for how to convert Docx to PDF in Python? No worries This article will explain how to use doc2pdf python for this conversion.
docx2pdf python library is really useful in easy Docx To PDF conversion. Docx2pdf gives privileges to use it via command line and python script both ways. Apart from it, docx2pdf gives multiple options for generating output PDFs using a specific configurable path and name.
Let’s go with docx2pdf implementation.
Firstly we need to install the python library docx2pdf. Use the below command for the pip package manager.
pip install docx2pdf
Open the command line (cmd) or console where your input Docx file is available.
If you have a single Docx file for conversion. Use the below command –
docx2pdf input_file.docx
This command will convert the Docx file with the same filename with PDF extension at the same physical address.
docx2pdf input_folder/
The above command will convert all the Docx file of the input_folder with their respective name and PDF extension.
It will be similar to above but little change in command.
docx2pdf input_folder/ out_folder/
docx2pdf input_file.docx out_folder/
This will create the corresponding PDF file from Docx at the configured location.
If you want to convert a Docx file into PDF with a specified name. Please refer to the command line statement.
docx2pdf input_file.docx User_define_name.pdf
If you are developing a feature on the python programming language. In the same feature/ project you need to convert the Docx file to PDF using python script/code. You may follow this section.
from docx2pdf import convert
convert("user_file.docx")
convert("user_input_dir/")
Here the argument is quite similar to the above command line section.
I hope you must like this article. In case you want to add your thoughts on Docx To PDF conversion using docx2pdf. Please comment below. Also if you need to convert PDF to Docx , Here is a amazing and short article for PDF to docx conversion using Python.
Keep reading other Python articles.
Thanks
Data Science Learner Team