Posted by a ceTe Software moderator
Hello,
Yes, you can use the DynamicPDF Viewer for .NET control in WPF to open the PDFs dynamically. Below are the steps to add the Viewer for .NET control to WPF. You will need to use the PdfDocument class which takes PDF file path, PDF contents in the form of stream or byte array and create object of PdfDocument class. Then use this PdfDocument object in Open method of Viewer object to display the PDF in the Viewer control. You can also refer to the documentation on opening PDF
here.
a)Reference the DynamicPDF 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)Add the Viewer control to the WindowsFormHost container and then open the PDF dynamically in Viewer using Open method. Below is code sample for it.
FileStream streamObj = new FileStream(@"C:\Temp\MyDocument.pdf", FileMode.Open);
PdfDocument pdf = new PdfDocument(streamObj);
this.windowsFormsHost1.Child = viewerObj;
viewerObj.Open(pdf);
Thanks,
ceTe Software Support Team.