2013-04-26 62 views
3

我創建了一個32位WPF application.It需要顯示在WebBrowser控件創建PDF PDF文件。 雖然這樣做,WPF web瀏覽器中打開在Adobe Reader窗口

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

它打開在Adobe Reader窗口PDF文件。

我需要的是PDF裏面應該沒有web瀏覽器在Adobe Reader窗口中打開。 我也試過WebBrowser.NavigateToStreamWebBrowser.Source但它不工作。

什麼可以解決這個問題?我期待着尋求幫助。

回答

4

你檢查,你已經安裝了Internet Explorer中的Adobe閱讀器?您還應該驗證您的Internet Explorer是否允許打開嵌入的PDF文件。

有時helpes,使用另一個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. 
    */ 
} 
+1

我發現使用幀間操作只是一個簡單的事情。使用adobe閱讀器添加用戶控件(Winform)並使用互操作性將其放入wpf – nullrefereceexception 2013-05-21 09:26:27

+0

@Bernhard Krenz,此代碼適用於32位窗口,但不適用於64位版本。 – MuhammadHani 2014-01-06 15:30:46

相關問題