实现功能:网页点击按钮后,后端触发exe文件,exe文件是用python编写,功能是把word文档转换为pdf文档。VS里面能正常运行,而在IIS里面浏览网页访问时,发生异常。网上找了办法,说是没有足够权限,我也都在应用池中设置了Local Service或administrator权限,MIME类型也有doc,exe,pdf 类型。
IIS里浏览,发现能触发exe文件,能遍历到文件夹的word文件,但是打开并转换pdf时,报:
doc.ExportAsFixedFormat(exportfile, constants.wdExportFormatPDF, AttributeError: 'NoneType' object has no attribute 'ExportAsFixedFormat' [12296]
python 程序:
import os from win32com.client import Dispatch, constants, gencache, DispatchEx
def doc(self, filename): ''' doc 和 docx 文件转换 ''' name = os.path.basename(filename).split('.')[0] + '.pdf' exportfile = os.path.join(self._export_folder, name) print('保存 PDF 文件:', exportfile) gencache.EnsureModule('{00020905-0000-0000-C000-000000000046}', 0, 8, 4) w = Dispatch("Word.Application") doc = w.Documents.Open(filename) doc.ExportAsFixedFormat(exportfile, constants.wdExportFormatPDF, Item=constants.wdExportDocumentWithMarkup, CreateBookmarks=constants.wdExportCreateHeadingBookmarks) w.Quit(constants.wdDoNotSaveChanges)