Error pywintypes.com_error occur when convert files docx to files pdf

Viewed 650

I am trying to convert from multiple docx files to multiple pdf files. But in the process I got an error (image below). I turned off the word application in the task manager and converted the file manually but still failed, the dialog sent me the message: "Export failed due to an unexpected error".

Image Error

My code here:

import os
from docx2pdf import convert
import time

path = "C:/Users/thuandao2/Desktop/test"
extension = [".docx", ".doc"]
for root, dirs, files in os.walk(path):
    for file in files:
        ext = os.path.splitext(file)[-1].lower()
        f_name = os.path.splitext(file)[0]
        if ext in extension:
            if "~" not in f_name:
                print("\nCovert " + str(file) + " to pdf: ")
                convert(os.path.join(root, file))
                time.sleep(5)

I used lib docx2pdf to covert. I think there is something wrong with my docx file which leads to the error but I don't know what it is.

I have also investigated on google and it seems this problem is very hard to detect root cause. I have found this link:

Export failed due to an unexpected error

1 Answers

As far as I know docx2pdf uses Microsoft Word for windows and LibreOffice Word for Ubuntu in the backend in order to convert the desired files to pdf. Thus in your case it may be possible that

1. You do not have Microsoft Word or the appropriate version/support for pdf conversion in it.

2. There is some issue while trying to access the Microsoft Word Application

Try updating your current version to the latest and check for the support of pdf conversion (manually using the application). We had the issue of lack of support and updating the version helped us get around the issue. We faced a similar issue and found out that this was the main reason.

There may be one more possibility : As suggested by you which is to renew the license.

Related