【问题标题】:MS Office Interop - DOCX to PDF with a passwordMS Office Interop - 带密码的 DOCX 到 PDF
【发布时间】:2021-08-27 04:19:11
【问题描述】:

我有 MS Office 2016,我想使用 Microsoft.Office.Interop.Word 将 DOCX 转换为带有密码的 PDF。

我在这里看到了很多代码示例,但没有人显示 PDF 的参数。

代码:

// Cast as Object for word Open method
    Object filename = (Object)wordFile.FullName;

    // Use the dummy value as a placeholder for optional arguments
    Document doc = word.Documents.Open(ref filename, ref oMissing,
        ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
        ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
        ref oMissing, ref oMissing, ref oMissing, ref oMissing);
    doc.Activate();

    object outputFileName = wordFile.FullName.Replace(".docx", ".pdf");
    object fileFormat = WdSaveFormat.wdFormatPDF;

    // Save document into PDF Format
    doc.SaveAs(ref outputFileName,
        ref fileFormat, ref oMissing, ref oMissing,
        ref oMissing, ref oMissing, ref oMissing, ref oMissing,
        ref oMissing, ref oMissing, ref oMissing, ref oMissing,
        ref oMissing, ref oMissing, ref oMissing, ref oMissing);

我可以将 DOCX 保存为 PDF。它有效。

但我想使用这个选项:另存为 -> PDF -> 选项 -> 使用密码加密文档。

请告诉我该怎么做?任何手册或参考资料。谢谢 [ [

【问题讨论】:

    标签: c# .net pdf encryption ms-word


    【解决方案1】:

    Microsoft Word API 不支持对以 Word 文档以外的任何格式保存的文档进行密码保护。

    【讨论】:

      【解决方案2】:

      我知道这是一个旧线程,但是对于来这里寻找答案的人,请查看https://www.pdflabs.com/tools/pdftk-server/ 以获取可以密码保护 pdf 文件的命令行工具。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-03-27
        • 1970-01-01
        • 2015-06-11
        • 1970-01-01
        • 2012-08-01
        • 1970-01-01
        • 2013-05-12
        相关资源
        最近更新 更多