I need to display a PDF in a WPF application. From all the reading I've been doing online, it seems the [only?] ways of displaying a PDF within a WPF application is via Adobe's controls or a WebBrowser control. I've tried to use Adobe's controls, however, I have been unable to add the Reader control because for some reason I can't find the it as something I can add into my Toolbox (even once adding the reference needed). I'm running Windows 7 (64-bit), VS2010, .NET 4.0, and have Adobe Acrobat 7.0 Professional and Adobe Acrobat 9 Pro Extended installed, if that has anything to do with it. So anyway, I decided to try it in a WebBrowser control hosted in a WindowsFormsHost. The XAML I have is this:
<WindowsFormsHost x:Name="FormsHost" Visibility="Visible" Grid.Column="1" Margin="7,0,0,0">
<WF:WebBrowser x:Name="WebBrowser" Dock="Fill" IsWebBrowserContextMenuEnabled="False" ScriptErrorsSuppressed="True" WebBrowserShortcutsEnabled="False" Margin="7,0,0,0" />
</WindowsFormsHost>
and then this in the C# code behind:
WebBrowser.Navigate(new System.Uri(FileName));
where FileName == the exact location of the .pdf file I need to display. However, when I run this all I see is a completely blank, white area where the WebBrowser is. I've also tried setting the .pdf file like this:
WebBrowser.Url = new System.Uri(FileName);
and I get the exact same thing. I know the PDF is being created in the correct location, as I can manually browse to it and open it fine.
Does anyone have any ideas as to why this isn't working? Or possibly why I don't seem to have the Reader control as an option? At this point, either solution would be fine, they just neither one seem to be working!
Thanks!
I'm afraid you are stuck using the WinForms PDF control and hosting it in your WPF application. Its a little annoying, but its not difficult to do. Here is an article and some sample source code:
http://hugeonion.com/2009/04/06/displaying-a-pdf-file-within-a-wpf-application/