Bootstrap

python Word转PDF

参考博客:https://blog.csdn.net/qq_40219176/article/details/78599980

import os, sys
from win32com.client import Dispatch, constants, gencache
input = r'F:\workshop\chineseocr-app\train\data\test\1.docx'
output =r'F:\workshop\chineseocr-app\train\data\test\1.pdf'
w = Dispatch("Word.Application")
try:
    doc = w.Documents.Open(input, ReadOnly=1)
    doc.ExportAsFixedFormat(output, constants.wdExportFormatPDF, \
       Item=constants.wdExportDocumentWithMarkup,
       CreateBookmarks=constants.wdExportCreateHeadingBookmarks)
except:
    print (' exception')
finally:
    w.Quit(constants.wdDoNotSaveChanges)
    
if os.path.isfile(output):
    print ('translate success')
else:
    print ('translate fail')

;