【问题标题】:Convert Word to PDF - Disable "save" Dialog将 Word 转换为 PDF - 禁用“保存”对话框
【发布时间】:2012-10-13 14:46:30
【问题描述】:

我有一个用 c# 编写的 Word 到 PDF 转换器,除了一件事之外它工作正常。有时(在某些 Word 文件上)背景中有一条消息,Save Changes in Source File -> YES NO CANCEL - 但我没有对源文件进行任何更改。我只想从 Word 文件创建一个 PDF 文件,而不做任何更改。

那么是否有可能禁用此提示,或自动设置为“否”。 ?

这是我的代码:

// Create an instance of Word.exe
        Microsoft.Office.Interop.Word._Application oWord = new  Microsoft.Office.Interop.Word.Application();

        // Make this instance of word invisible
        oWord.Visible = false;

        oWord.DisplayAlerts = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;

        oWord.Options.SavePropertiesPrompt = false;
        oWord.Options.SaveNormalPrompt = false;

        // Interop requires objects.
        object oMissing = System.Reflection.Missing.Value;
        object isVisible = true;
        object readOnly = true;
        object oInput = input;
        object oOutput = output;
        object oFormat = format;

        // Load a document into our instance of word.exe
        Microsoft.Office.Interop.Word._Document oDoc = oWord.Documents.Open(ref oInput, ref oMissing, ref readOnly, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref isVisible, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

        // Make this document the active document.
        oDoc.Activate();

        // Save this document in Word 2003 format.
        oDoc.SaveAs(ref oOutput, ref oFormat, 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);

        // Always close Word.exe.
        oWord.Quit(ref oMissing, ref oMissing, ref oMissing);

【问题讨论】:

  • 这不会将 Word 文档转换为 PDF - 它只是打开一个 Word 文档并保存副本为 Word 2003 (.doc)格式。
  • 取决于“格式”的值。如果这是 wdFormatPDF (17),它应该创建一个 PDF 文件(Office 2007 及更高版本)。

标签: c# pdf ms-word


【解决方案1】:

您是否尝试将 false 作为第一个参数传递给 Quit?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-21
    • 1970-01-01
    • 1970-01-01
    • 2015-04-20
    • 1970-01-01
    • 1970-01-01
    • 2013-03-29
    • 1970-01-01
    相关资源
    最近更新 更多