Predictive Hacks

How to Convert an MS Word File to PDF in Python

We can convert MS Word files (.docx) to .pdf on Windows or macOS, but the Microsoft Word must be installed. On Windows, this is implemented via win32com while on macOS this is implemented via JXA (Javascript for Automation, aka AppleScript in JS).

Let’s see an example.

from docx2pdf import convert

# docx file path
word_file = '/myinput/Doc1.docx'

# pdf file path (output)
pdf_file = '/myoutput/Doc1.pdf'

convert(word_file, pdf_file)

Share This Post

Share on facebook
Share on linkedin
Share on twitter
Share on email

Subscribe To Our Newsletter

Get updates and learn from the best

More To Explore

Python

Image Captioning with HuggingFace

Image captioning with AI is a fascinating application of artificial intelligence (AI) that involves generating textual descriptions for images automatically.

Python

Intro to Chatbots with HuggingFace

In this tutorial, we will show you how to use the Transformers library from HuggingFace to build chatbot pipelines. Let’s