WPF webbrowser opens PDF file in Adobe reader window

pdf, wpf

Solution

Have you checked, that you have the Adobe reader installed for the Internet Explorer? You should also verify, that your Internet Explorer is allowed to open PDF-Files embedded.

Sometimes it helpes, to use another Internet Explorer Rendering Engine. This can be archived in with the following code (be warned: Administrator rights are needed for that).

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.
    */
}

Problem

I am creating one 32bit WPF application.It needs to show created PDF in WebBrowser control. While doing , ``` "WebBrowser.Navigate(new Url("D:\\TestPDF\\MyDocument.pdf"))"; ``` it opens PDF file in Adobe reader window. My Need is PDF should be opened inside WebBrowser not in Adobe reader window. I have also tried `WebBrowser.NavigateToStream` and `WebBrowser.Source` but its not working. What can be solution for this? I am looking forward for help.

Original source