簡體   English   中英

MS Office 互操作 - DOCX 到 PDF 帶密碼

[英]MS Office Interop - DOCX to PDF with a password

我有 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。 有用。

但我想使用這個選項:SaveAs -> PDF -> Options -> Encrypt the document with a password。

請告訴我該怎么做? 任何手冊或參考資料。 謝謝 [ [

Microsoft Word API 不支持以 Word 文檔以外的任何格式保存的文檔的密碼保護。

我知道這是一個舊線程,但是對於來這里尋找答案的人,請查看https://www.pdflabs.com/tools/pdftk-server/以獲取可以密碼保護 pdf 文件的命令行工具。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM