Foxit SDK .NET

Can Foxit PDF Viewer for .NET SDK be incorporated in a WPF window (Via WinFormsHost)?

If you would like to use Viewer control in WPF, it is possible to use WindowsFormHost control to include Viewer in WPF form. You can refer to the documentation on including windows controls in WPF through WindowsFormHost in the following link: https://msdn.microsoft.com/en-us/library/ms742875(v=vs.110).aspx. However, please be aware that Foxit PDF Viewer for .NET is not designed for WPF and we do not officially support it.

How to resize the viewer control in WPF

Regarding the resizing of viewer control, you will need to set the height for the viewer control as per the WindowsFormHost control dynamically and this will work for you. Below is the highlighted code sample for setting height for the Viewer control.

Below are the steps to use the Viewer for .NET in WPF.

a) Reference the Foxit PDF Viewer for .NET DLL in your WPF application.
b) Add reference to the System.Windows.Forms and WindowsFormsIntegration assemblies.
c) Open the MainWindow.xaml in designer mode.
d) Add a WindowsFormHost WPF control to the MainWindow.
e) Initialize the Viewer control in MainWindow class constructor.
f) You can dynamically add it to the WindowsFormHost in desired events.

The sample code below shows how to achieve that in your script:

private void Window_Loaded(object sender, RoutedEventArgs e)
{ 
  PdfViewer viewerObj = new PdfViewer(); 
  PdfDocument pdf = new PdfDocument("DocumentB.pdf"); 
  windowsFormsHost1.Child = viewerObj; 
  windowsFormsHost1.Width = this.Width; 
  windowsFormsHost1.Height = this.Height; 
  viewerObj.Width = (int)windowsFormsHost1.Width; 
  viewerObj.Height = (int)windowsFormsHost1.Height; 
  viewerObj.Open(pdf); 
}

Updated on September 14, 2017

Was this article helpful?
Thanks for your feedback. If you have a comment on how to improve the article, you can write it here: