3

我正在创建一个 32 位 WPF 应用程序。它需要在 WebBrowser 控件中显示创建的 PDF。做的时候,

"WebBrowser.Navigate(new Url("D:\\TestPDF\\MyDocument.pdf"))";

它在 Adob​​e 阅读器窗口中打开 PDF 文件。

我的需要是 PDF 应该在 WebBrowser 中而不是在 Adob​​e 阅读器窗口中打开。我也尝试过WebBrowser.NavigateToStreamWebBrowser.Source但它不起作用。

有什么办法可以解决这个问题?我期待着帮助。

4

1 回答 1

4

您是否检查过是否为 Internet Explorer 安装了 Adob​​e 阅读器?您还应该验证您的 Internet Explorer 是否允许打开嵌入的 PDF 文件。

有时,使用另一个 Internet Explorer 渲染引擎会有所帮助。这可以使用以下代码存档(警告:需要管理员权限)。

private void CheckAndFixWebBrowserRenderingEngine()
{
    RegistryKey baseRegistryKey = Registry.LocalMachine;
    string renderingEngineSubKeyString = @"SOFTWARE";

    // 64bit operationg systems have another registry path
    if (Environment.Is64BitOperatingSystem)
    {
        renderingEngineSubKeyString += @"\Wow6432Node";
    }

    renderingEngineSubKeyString += @"\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION";

    var assemblyValueKey = Path.GetFileName(App.ResourceAssembly.Location);
    var renderingEngingeValue = 9999; // check other values below

    try
    {
        RegistryKey sk1 = baseRegistryKey.CreateSubKey(renderingEngineSubKeyString);

        var value = sk1.GetValue(assemblyValueKey);
        if (value == null || value.ToString() != renderingEngingeValue.ToString())
        {
            sk1.SetValue(assemblyValueKey, renderingEngingeValue);

            LogHandler.Instance.Add(string.Format("Did update webbrowser rendering engine from {0} to 9000.", value == null ? "[missing]" : value));
        }
    }
    catch (Exception ex)
    {
        LogHandler.Instance.Add("Could not check webbrowser rendering engine in registry.");
        LogHandler.Instance.Add(ex.ToString(), Logging.LoggingPriorities.Exception);
    }

    /*
    9999 (0x270F) 
    Internet Explorer 9. Webpages are displayed in IE9 Standards mode, regardless of the !DOCTYPE directive.

    9000 (0x2328) 
    Internet Explorer 9. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode.

    8888 (0x22B8) 
    Webpages are displayed in IE8 Standards mode, regardless of the !DOCTYPE directive.

    8000 (0x1F40) 
    Webpages containing standards-based !DOCTYPE directives are displayed in IE8 mode.

    7000 (0x1B58) 
    Webpages containing standards-based !DOCTYPE directives are displayed in IE7 Standards mode.
    */
}
于 2013-04-26T10:01:23.123 回答