Skip to main content

Displaying a PDF file within a WPF application

I had a need to view PDF files directly within a WPF application for a projcect.So i found an easy way to do that.The trick is to use the WinForms support in WPF ala the WindowsFormHost control.
PDF Viewer




1. Creating the “pdfViewer” user control
a. Right click your Toolbox and select "Add Tab". Enter in the name "Adobe" or whatever you want to call the tab and hit enter.
b. Next right click in the area underneath your new tab, and select "Choose Items". Click on the "COM Components" tab and select "Adobe PDF Reader".
c. Add a Windows User Control to your project. Do not add a WPF user control "User Control (WPF)" instead select the plain "User Control".
d.Once you've added your user control simply click and drag the "Adobe PDF Reader" item from your toolbox (added above) onto your user control.
e. Now you need to load the relevant PDF into the control. To do this view the code of your User Control and change the default constructor accordingly
1
2. Creating the “PDF Viewer” WPF application
a. We need to drag a "WindowsFormsHost" item from our tool box onto our WPF form. This will host the user control we created above.
b. To load the PDF, go to the code behind of our MainWindow (default WPF form) and change the constructor as follows
2

That’s all.We just created a pdf viewer using WPF.

Comments