How to display PDF in web browser control instead of opening Acrobat Reader

后端 未结 1 1336
我在风中等你
我在风中等你 2020-12-19 10:23

i am using Acrobat Reader 11.0.3 and window 7, Visual studio 2012 and already enabled Acrobat Reader in Manage Addon

and follow WPF webbrowser opens PDF file in Ado

相关标签:
1条回答
  • 2020-12-19 10:26

    You could generate a temp HTML file to embed the desired 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>
    

    What's interesting, to make it work with a local (file://) PDF document, I had to specify both data attribute and src param. When it was served via http from localhost, the data alone was just enough.

    UPDATE: I could not tell why this doesn't work for the OP, so I've cooked up a very basic C# WebBrowser project demo'ing this. It works quite reliably in my environment (Win8, IE10, Acrobat Reader 11.0.3).

    UPDATE: I think I understand why this is happening. Your project uses WPF, while my sample uses Winforms. Sorry, I did not notice this in the first place. WPF WebBrowser has a different security model, it runs in IE Protected Mode by default.

    With WPF WebBrowser, I've managed to get rid of the prompt (note <!-- saved from url=(0016)http://localhost -->), but I do confirm the Acrobat Reader control just hangs loading the file every now and then:

    <!-- 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 control is known to have issues with Protected Mode. Rather than trying to find a workaround for this, it may be easier to host Acrobat Reader ActiveX control directly in your WPF project. Here's how it can be done:

    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 讨论(0)
提交回复
热议问题