You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows服务器IIS部署Flask应用:Docx转Pdf方案求助

在IIS部署的Flask应用中实现Docx转Pdf的问题与处理

问题背景

我在Windows服务器的IIS上部署了Flask应用,需求是实现不修改原Docx文件的转Pdf功能。

尝试方案与报错

最初通过comtypes调用Word.Application编写转换代码,但因Windows权限限制执行失败,报错信息:(-2147024891, 'Access is denied', None, None)。

期间也寻找过可通过IIS请求调用的转换工具,但这类工具大多需要授权许可。

后续处理与结论

  • 若要继续使用Word.Application实现转换,需修改Windows组件服务中Microsoft Word的IIS及默认应用用户权限;
  • 我转而采用LibreOffice进行转换,但该工具存在无法1:1还原文档格式的缺陷,目前已关闭此话题。

附尝试的代码

def doc2pdf(doc_name, pdf_name, font_size=8):

    pythoncom.CoInitialize()
    word = client.DispatchEx("Word.Application")
    if os.path.exists(pdf_name):
        os.remove(pdf_name)
    worddoc = word.Documents.Open(doc_name, ReadOnly=1)
    worddoc.Content.Font.Size = font_size
    try:
        worddoc.SaveAs(pdf_name, FileFormat=17)
    except Exception as e:
        createText('wordToPdfException', f"{e}")
    worddoc.Close()
    # Quit the Word application
    word.Quit()
    pythoncom.CoUninitialize()
    return pdf_name

内容的提问来源于stack exchange,提问作者Fatih Enes

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 13:25:57