转换为XPS的Word文件使超链接处于非活动状态

时间:2015-02-10 19:37:34

标签: c# wpf ms-word xps

我有一个WPF application,我以word document格式向用户展示了XPS。 我使用Microsoft.Office.Interop.Word。代码如下

但是word文件中的超链接是不活动的(不可点击,也不会带我到他们链接的地方)。我该如何解决这个问题?

public static XpsDocument ConvertWordToXps(string wordFilename, string xpsFilename)
{
    // Create a WordApplication and host word document 
    var wordApp = new Application();
    wordApp.Application.Visible = false;
    wordApp.Documents.Open(wordFilename);

    // To Invisible the word document 
    wordApp.Application.Visible = false;

    // Minimize the opened word document 
    wordApp.WindowState = WdWindowState.wdWindowStateMinimize;

    Document doc = wordApp.ActiveDocument;

    doc.SaveAs(xpsFilename, WdSaveFormat.wdFormatXPS);

    var xpsDocument = new XpsDocument(xpsFilename, FileAccess.Read);
    return xpsDocument;

}

1 个答案:

答案 0 :(得分:1)

必须为DocumentViewer对象(documentviewWord)编写一个事件处理程序来处理超链接

private void link_RequestNavigate(object sender, RequestNavigateEventArgs e)
{
    System.Diagnostics.Process.Start(e.Uri.AbsoluteUri);
}

在View构造函数中

documentviewWord.AddHandler(Hyperlink.RequestNavigateEvent, new RequestNavigateEventHandler(link_RequestNavigate));