I have a WPF C# .NET 4.0. solution in VS2010 on Windows 7. It contains a WPF hosting project and a WindowsFormsControl project where I've created a UserControl that should display an Acrobat CAcroAVDoc object from the Interop.Acrobat SDK com object (latest).
The WPF Project contains this code to open a file which actually creates a new WindowsFormsUserControl (PDFViewerControl) that in turns opens the file, the UserControl is then added to a WindowsFormHost object in WPF main form.
private void OpenFile(FileItem file)
{
if (file.Extension.ToLower() == ".pdf")
{
System.Windows.Forms.Integration.WindowsFormsHost host = new System.Windows.Forms.Integration.WindowsFormsHost();
WindowsFormsControls.PDFViewerControl viewer = new WindowsFormsControls.PDFViewerControl();
viewer.Show();
Boolean result = viewer.OpenFile(file.Path);
if (!result)
{
MessageBox.Show("Error opening document");
}
host.Child = viewer;
this.pdfViewWpf.Children.Add(host);
viewer.Show();
}
}
The PDFViewerControl OpenFile method contains this code and returns True when opening a PDF document via OpenInWindowEx.
public Boolean OpenFile(String filename)
{
CAcroAVDoc doc = Activator.CreateInstance(Type.GetTypeFromProgID("AcroExch.AVDoc")) as CAcroAVDoc;
bool res = doc.OpenInWindowEx(filename, this.Handle.ToInt32(), 2, 1, 0, (short)Acrobat.PDViewMode.PDUseBookmarks, (short)Acrobat.AVZoomType.AVZoomFitWidth, 0, 0, 0);
return res;
}
Unfortunately though the PDF cannot be seen in WPF Host object. If I place a LABEL on the windows forms user control, the label will show in WPF. It seems the OpenInWindowEx is not loading a PDF object onto the user control. Perhaps I need a resize method and event?
I cannot locate any object on the PDFViewerControl user control that resembles a PDF document through debug.
Any help/pointers much appreciated.
this.Handle.ToInt32() does have a seemingly valid value (ie window handle).
this.pdfViewWpf is a XAML <Grid>
Dominic