Add A PDF Viewer To A WPF Application
Answer :
As already suggested by @NawedNabiZada, one tried and straightforward way is to use embedded InternetExplorer to show Adobe PDF Reader
ActiveX control. So it assumes you are running on Windows and have Adobe PDF Reader
installed.
Then you create a user control, window etc. that contains following control:
<WebBrowser x:Name="pdfWebViewer"></WebBrowser>
In the constructor navigate to blank page:
pdfWebViewer.Navigate(new Uri("about:blank"));
To load a PDF document to that control use this simple code:
pdfWebViewer.Navigate(fullPathToPDF);
This approach is used by many Windows software not only WPF apps including SAP client, but has a hidden problem, see this question.
The Adobe PDF Reader Addon in Internet Explorer must be enabled for this to work. There are various problems with Acrobat Reader XI, better to use DC version. To enable Adobe PDF go to IE settings, add-ons and find Adobe PDF Reader and enable it (AR XI and above).
For me this was the preferred way compared to the code project article you linked.
For anyone stumbling upon this, and in need of a litte bit more control than with the WebBrowser: It's quite easy to make your own PDF viewer with Windows 10 APIs. I wrote a blog on how to do it. You can easily add other features to it like drawing on top (signature) of it and so on.
The code is available on github.
However for super advanced features, you probably will need one of those fancy expensive libraries.
It is also possible by the cefsharp Web Browser.
it includes embedded modules for PDF, so you dont need Acrobat-Reader, or any other ActiveX.
Get-Started CefSharp in WPF
Comments
Post a Comment