View PDF in WPF without using WindowsFormsHost

Are there any built-in WPF controls for displaying PDF files? I am writing a program that will download a PDF file and then display additional labels on top of it.

Using WindowsFormsHost (http://hugeonion.com/2009/04/06/displaying-a-pdf-file-within-a-wpf-application/) will not work because the WindowsFormsHost control is always displayed on top of all other controls WPF in the window. This will not allow me to see my notes via PDF.

Converting a PDF to a bitmap with the level of detail I need will create an oversized file.

The WebBrowser control does not programmatically change or scale pages. I also cannot remove the Adobe toolbars.

Any third-party libraries that I used should be free (like in beer).

+6
source share
3 answers

If you have any plug-in for viewing PDF (for example, Acrobat Reader) for IE on your computer ...

<Grid> <WebBrowser x:Name="WebBrowser1" Source="C:\Temp\Test.pdf"/> </Grid> 

works great ...

+6
source

Unfortunately, I still do not have enough reputation to make a comment, so I will put it as an answer. I had a very similar problem with Flash recently, and I ended up using WindowsFormsHost and Overlays / Adorners . Just my 2cents.

Here XAML creates the overlay as a popup:

  <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 simplicity, I reduced my overlay to one ellipse. The web browser is hosted by WindowsFormsHost. Here its code is placed and displayed:

  public MainWindow() { InitializeComponent(); puOverlay.VerticalOffset = -60; puOverlay.HorizontalOffset = (wbMain.ActualWidth / 2) - 20; puOverlay.IsOpen = true; ... } 

Quite simply, however, do not hesitate to ask, something else is unclear.

+1
source

I have not found any good free third-party WPF controls that work well. Telerik has a pdf viewer, but it does not do all types and will not do large documents for me. I tried Syncfusion too, and that too was a mistake. I ended up using WindowsFormsHost with another third-party Windows form developer. They say they are making a version of WPF.

Now there are others that you have to pay for each server installation, which may be good, I just can’t work with it.

0
source

Source: https://habr.com/ru/post/908088/


All Articles