如何

2013-08-05 83 views
5

我使用的Acrobat Reader 11.0.3和窗口7時,Visual Studio 2012,並已顯示在Web瀏覽器控件PDF而不是打開Acrobat Reader軟件的啓用Acrobat Reader軟件中管理附加組件如何

,並按照WPF webbrowser opens PDF file in Adobe reader window

仍然有錯誤嘗試兩種方法

導航到該網頁被取消後 即使使用管理員帳戶打開WPF程序

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 = System.IO.Path.GetFileName(App.ResourceAssembly.Location); 
      var assemblyValueKey = System.IO.Path.GetFileName(System.Windows.Application.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. 
      */ 
     } 

     public ReportForm() 
     { 
      this.formID = "Test Report"; 
      //base.Initialization(); 
      InitializeComponent(); 
      CheckAndFixWebBrowserRenderingEngine(); 

      String PDFPath = @"C:\Users\LAB-User2\Downloads\Elimination_Methods_in_Polynomial_Computer_Alge(Bookos.org).pdf"; 
      WebBro1.Navigate("file:///" + PDFPath); 

方法2

我也有試過其中添加引用windowformintegration和使用的WinForm的用戶控件,它只是在一個獨立的WPF小項目 工作時,在我的大項目這個整合的另一種方法,它得到了上面的錯誤

String PDFPath = @"C:\Users\LAB-User2\Downloads\Elimination_Methods_in_Polynomial_Computer_Alge(Bookos.org).pdf"; 
      //WebBro1.Navigate("file:///" + PDFPath); 
      webBrowser1.Navigate("file:///" + PDFPath); 

private System.Windows.Forms.WebBrowser webBrowser1; 
<WindowsFormsHost Margin="1" x:Name="windowsFormsHost1" Height="600" HorizontalAlignment="Left" VerticalAlignment="Bottom" Width="1000"/> 

var uc = new UserControl1(); 
      this.windowsFormsHost1.Child = uc; 


application.UI.CreateNewForm("Test Report", new Client.Reporting.Pages2.ClientStatement.ReportForm()); 

public partial class ReportForm : BaseForm 

public void CreateNewForm(string title, BaseForm form) 
    mw.CreateNewForm(title, form); 


public class BaseMainWindow : MetroWindow 
    { 
     public virtual void CreateNewForm(string title, BaseForm form) 
     { 

     } 

更新:它要求允許在HTML文件塊內容和灰色屏幕在Internet Explorer之前集成到大項目

<html> 
<body> 

<object 
    classid="clsid:ca8a9780-280d-11cf-a24d-444553540000" id="pdf1" 
    type="application/pdf" 
    data="C:\Users\LAB-User2\Downloads\Elimination_Methods_in_Polynomial_Computer_Alge(Bookos.org).pdf" 
    style="width: 100%; height: 100%"> 

<param name="src" "value="C:\Users\LAB-User2\Downloads\Elimination_Methods_in_Polynomial_Computer_Alge(Bookos.org).pdf"></param> 

</object> 

</body> 
</html> 

enter image description here

更新:當運行大型的WPF項目的代碼,它顯示一個紅叉 enter image description here

更新:更新的HTML後,它工作在獨立的HTML文件,但集成在WPF大項目,它未能顯示,只顯示一個紅色十字

String temphtml = "<!-- saved from url=(0016)http://localhost --><body style=\"border: 0; margin: 0; padding: 0\"><object classid=\"clsid:ca8a9780-280d-11cf-a24d-444553540000\" id=\"pdf1\" type=\"application/pdf\" data=\"02_LAB_LeaveApplication.pdf\" style=\"width: 100%; height: 100%; border: 0; margin: 0; padding: 0\"></object><script>window.onload = function(){ window.focus();pdf1.setActive(); }</script></body>"; 
      System.IO.File.WriteAllText(@"C:\Users\LAB-User2\Desktop\vpfs-ivpfs-client\iVPFS_Client\Application\bin\Debug\a.html", temphtml);    
      this.WebBro1.Navigate(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "a.html")); 

更新雖然運行從CodeProject上下載的項目,它顯示一個錯誤,然後CA n顯示pdf並在打開時有幾次空白,然後我將代碼和庫複製到一個小WPF項目並運行,它也有錯誤出來,只顯示白色空白https://docs.google.com/file/d/0Bxs_ao6uuBDUeV8yREVBOExSbW8/edit?usp=sharing

+0

你發現了它,而不是在你的大項目中的工作?我也有完全一樣的問題。我在我的真實項目中有一個(黑色)十字,但在Prototyp應用程序中它工作得很好。 – Florian

回答

3

您可以生成一個臨時HTML文件嵌入所需的PDF:

<body> 

<object 
    classid="clsid:ca8a9780-280d-11cf-a24d-444553540000" id="pdf1" 
    type="application/pdf" 
    data="test.pdf" 
    style="width: 100%; height: 100%"> 

<param name="src" "value"="test.pdf"></param> 

</object> 

</body> 

有趣,使之與當地的合作(文件://)的PDF文檔,我不得不同時指定數據屬性和SRC PARAM。當它通過本地主機的http服務時,單獨的數據就足夠了。

UPDATE:我不知道爲什麼這不適用於OP,所以我已經制作了一個非常基本的C# WebBrowser project demo'ing這個。它在我的環境中運行得非常可靠(Win8,IE10,Acrobat Reader 11.0.3)。

UPDATE:我想我明白爲什麼會發生這種情況。您的項目使用WPF,而我的示例使用Winforms。對不起,我沒有注意到這一點。 WPF WebBrowser具有不同的security model,它默認運行在IE保護模式下。

使用WPF web瀏覽器,我已經成功地擺脫了提示(注意<!-- saved from url=(0016)http://localhost -->)的,但我確認了Acrobat Reader軟件控制只是掛加載文件飄飛:

<!-- saved from url=(0016)http://localhost --> 

<body style="border: 0; margin: 0; padding: 0"> 

<object 
    classid="clsid:ca8a9780-280d-11cf-a24d-444553540000" id="pdf1" 
    style="width: 100%; height: 100%; border: 0; margin: 0; padding: 0"> 

    <param name="src" "value"="test.pdf"></param> 

</object> 

<script> 
window.onload = function() 
{ 
    window.focus(); 
    pdf1.setActive(); 
} 
</script> 

</body> 

Acrobat Reader軟件控制is known在保護模式下有問題。與其試圖爲此尋找解決方法,可能更容易將Acrobat Reader ActiveX控件直接放置在您的WPF項目中。下面是它如何做到:

http://www.codeproject.com/Articles/380019/Using-Adobe-Reader-in-a-WPF-app http://hugeonion.com/2009/04/06/displaying-a-pdf-file-within-a-wpf-application/

+0

它在html文件中嘗試後變成灰色屏幕,哪裏出錯? – ControlPoly

+0

你能否確認.PDF和.HTML文件在同一個文件夾中?以上測試是在Win8,IE10和Acrobat Reader 11.0.3下爲我工作的。 – Noseratio

+0

我確認pdf和html在同一個文件夾中 – ControlPoly