Are there any native WPF controls for displaying PDFs? I am writing a program that will load a PDF file and then display extra notations on top of it.
Using a WindowsFormsHost (http://hugeonion.com/2009/04/06/displaying-a-pdf-file-within-a-wpf-application/) won't work because a WindowsFormsHost control always displays on top of all other WPF controls in a window. This won't allow my notations to be seen over the PDF.
Converting the PDF into a raster image with the level of zoom detail that I need would create a file that is too large.
The WebBrowser control doesn't allow the pages to be changed or zoomed programmatically. I also can't remove the Adobe toolbars.
Any third-party libraries I used would need to be free (as in beer).
Provided that you have some PDF viewer plugin (such as Acrobat Reader) for IE on your machine...
<Grid>
<WebBrowser x:Name="WebBrowser1"
Source="C:\Temp\Test.pdf"/>
</Grid>
works just fine...
Unfortunately I don't have enough reputations yet to make a comment, so I will put it as an answer. I have had a very similar problem with Flash recently and I ended up using WindowsFormsHost and Overlays/Adorners. Just my 2cents.
Here is XAML creating an overlay as a popup window:
<Grid>
<Canvas >
<WebBrowser x:Name="wbMain" Width="800" Height="500"></WebBrowser>
<Popup x:Name="puOverlay" AllowsTransparency="True" Placement="Bottom" PlacementTarget="{Binding ElementName=wbMain}">
<Ellipse Canvas.Left="0" Canvas.Top="0" Height="50" Name="headEllipse" Stroke="Black" Fill="Orange" Width="50" Canvas.ZIndex="5"/>
</Popup>
<Ellipse Canvas.Left="0" Canvas.Top="0" Height="50" Name="headEllipse1" Stroke="Black" Fill="Orange" Width="50" Canvas.ZIndex="5"/>
</Canvas>
</Grid>
For the simplicity sake I reduced my overlay to one ellipse. Web Browser is hosted in WindowsFormsHost. Here is the code placing and showing it:
public MainWindow()
{
InitializeComponent();
puOverlay.VerticalOffset = -60;
puOverlay.HorizontalOffset = (wbMain.ActualWidth / 2) - 20;
puOverlay.IsOpen = true;
...
}
Pretty simple, however don't hesitate to ask if something is still unclear.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With