I am currently trying to convert some word documents to PDF using python, some of the files converted successfully with the code I have while I got the following error messages on other files:
Error 1: some files reported
com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Word', 'String is longer than 255 characters', 'wdmain11.chm', 41873, -2146819183), None)
Error 2: Some reported
com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Word', 'Command failed', 'wdmain11.chm', 36966, -2146824090), None)
Error 3: Some reported
AttributeError: 'NoneType' object has no attribute 'SaveAs'
Below is the code I am using, any idea why this is happening:
from docx2pdf import convert
def convert_word_to_pdf(word_path):
pdf_path = word_path.replace(".docx", ".pdf")
convert(word_path, pdf_path)
word_path = '*file_path*'
convert_word_to_pdf(word_path)
Thank you for your support
I expected the python code above to convert all the files to PDF.