Skip to main content

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…

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
Fig.1. Python Code

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.

Fig.2. CLI commands

To implement this using GUI, you must install PyQt5:

pip install PyQt5
Fig.3. Drag drop ft. to convert docx to pdf in batch

Output:

Fig.4. Main window where user has to drag and drop files
Fig.5. Processing window
Fig.6. Docx files get converted into PDF

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
Fig.7. Another way to convert Docx file into PDF


Comments

Popular posts from this blog

How to use Chess com API using Python

  How to use Chess com API using Python Chess is an amazing strategy-based game and if you have been following the recent boom of online chess then welcome to the chess club. Online chess is amazing since it allows you to play with a random stranger at your level or stockfish (computer). There are many popular online chess websites like lichess.org, chess.com, playchess.com, and newly created kasparovchess.com. Today we will be seeing how to use chess.com API for getting players' stats. You can create software and get affiliates from them (check out the link below), so share it with them if you are planning to create something. Before you start make sure you have the following things: Pre-requirements Postman Anaconda or mini conda or Python idle Any text editor of your choice Pretty good? Now let’s download the JSON file that chess com developers have already made for us from here and then you import it to the Postman. This just helps you with prewritten get methods so that ...

Create your own YouTube video and playlist downloader using QT designer in Python

Create your own YouTube video and playlist downloader using QT designer in Python The code for this software is available on my GitHub, the link is given below. Create your own YouTube video and playlist downloader using QT designer in Python This is the thing we are trying to make today for this article The code for this software is available on my GitHub, the link is given below. If you haven’t checked out my previous article on the same topic but not the GUI version, please check it out. 3 ways to download YouTube playlists at once using Python Have you guys ever wanted to download your entire youtube playlist? rahulbhatt1899.medium.com So before starting to code let's check if you have all the requirements beforehand: Pre-requirements : Qt designer Anaconda or mini conda or python 3.7 compiler Any text editor of your choice Libraries to download: Pytube Ffmpy PyQt5 This would be sectioned into the following structure: Creating the UI in Qt designer Converting UI file int...

Authentication Using Passport JS

Authentication is big and most complicated part of an application, but it is also the  preponderance  part of any web app/software in general. Passport JS Passport JS is a widely popular authentication module for  Node js.  The sole purpose is to authenticate requests and is based on the idea of pluggable authentication strategies ( including local strategy, there are more than 500 strategies currently  available  ). When using third party application Your app never receives your password  thus freeing the developer from the burden of security related to handling and storing passwords. The Passport authentication and its strategy will include protection against attacks like “man in the middle” and other vectors an attacker might exploit. We are going to use Facebook strategy, for now, to install Passport and Facebook strategy type in the following command: Next, we are going to write the authentication code, and we’ll be creating a different module cal...