views:

1581

answers:

1

Hi,

we are currently using a winforms WebBrowser control in our app in a WindowsFormsHost and printing by calling 'WebBrowser.ShowPrintDialog()' We have an issue with this in that the dialog does not appear to be modal and the parent window can be dismissed causing issues if a print is later attempted.

I was looking at the new wpf webbrowser control in the hope that they will have fixed this issue when doing a similar thing themselves, but can find no way to print from it..

I found someone online talking of doing this:

        PrintDialog printDialog = new PrintDialog();
        printDialog.PrintDocument(((IDocumentPaginatorSource)webBrowser.Document).DocumentPaginator, "My App");

but this throws an exception as the WebBrowser.Document does not support the IDocumentPaginatorSource interface.

Is there any way I can print from the wpf web browser control?

thanks

+1  A: 

I am using this, and it works:

    mshtml.IHTMLDocument2 doc = webBrowser.Document as mshtml.IHTMLDocument2;
    doc.execCommand("Print", true, null);
Botz3000
thanks, that worked. Unfortunately I still have the problem where I can interact with (and dismiss) the UI that initiates the print even though the print dialog is still there. Do you have this issue? Any ideas on how to get an event when the print dialog is closed?
Trev
I don't know, but i'm pretty sure the print dialog is initiated from unmanaged code so that it might need some more work to listen for events like that.
Botz3000