3 Methods to convert Docx files into PDF files using Python
3 Methods to convert Docx files into PDF files using Python

Have you always wanted to convert Docx files into pdf in a batch? If yes, these python scripts will make your life much more comfortable.
The two methods of which one includes GUI another doesn’t. The following one is slightly different and requires a Word application installed on your system.To install docx2pdf:
The first one will be without GUI:
pip install docx2pdf

Explanation: The convert() function takes two arguments that are the abs path of the file you want to convert and where you want to save. You can do batch convert by providing the folder path.
This library also allows using CLI instead of writing a code in a separate file.

To implement this using GUI, you must install PyQt5:
pip install PyQt5

Output:



Explanation: There is a lot of theory to cover all the functions used, but we will only see the important ones. You can get more information by checking out the references attached below.
QMimeData belongs to the QtCore module stores data on a clipboard then is used in the drag and drop process.
DragEnterEvent: provides an event sent to the target widget as dragging action enters it.
DragMoveEvent: is used when the drag and drop action is in progress.
DropEvent: is the event that occurs when the drop gets completed.
hasUrls(): Returns true if the object can return a list of URLs; else returns false.
The basic idea is to use PyQt5 to create a GUI, PyQt.QtWidgets to use QListWidget and its functions and PyQt5.QtCore to get the URI-list of the files, basically the location of the file, and then converting the file at this location.
There is also another way to convert Docx files into PDF that requires a word application installed on your system.
Install this first:
pip install comtypes

References:
Convert docx to pdf on Windows or macOS directly using Microsoft Word (must be installed). On Windows, this is…pypi.org
Comments
Post a Comment