Convert Word (.docx) to PDF Using WPS in Python – Python Tutorial

By | February 10, 2022

In order to convert word (.docx) file to pdf in python, we can use docx2pdf library. Here is the tutorial:

Convert Word (.docx) to PDF in Python: A Step Guide – Python Tutorial

However, docx2pdf library need word office application that has installed in your computer. If no word office application, you may get this error:

pywintypes.com_error: (-2147221005, ‘Invalid class string’, None, None)

How to fix this error?

Method 1: install Microsoft Office in your computer.

Method 2: install wps application.

In this tutorial, we will introduce how to use wps to convert a word file to pdf in python.

How to use wps to convert word to pdf in python?

We also use python docx2pdf library, however, we need edit windows() function in docx2pdf, here is an example:

word = win32com.client.Dispatch("kwps.Application")

How to use wps to convert word to pdf in python

Then, we can use docx2pdf to convert a word file to pdf based on WPS application.

Leave a Reply