views:

454

answers:

1

I'm currently attempting to print a document from WPF. I'm using the web browser because it contains an active x control which has the autodesk plugin which I need to view the document.

I'm aware that WPF doesn't directly support web browser but I've just integrated the Windows Forms library for this. I've managed to get the code running and even printing, however the document that prints is blank.

I'm not sure if it could possibly be a conflict between the Windows Forms library and WPF; I'm navigating to the document and only printing once it's loaded with no errors thrown.

Here's the code I'm using:

    private void btnPrint_Click(object sender, RoutedEventArgs e)
    {
        System.Windows.Forms.WebBrowser w = new System.Windows.Forms.WebBrowser();

        Uri uri = new Uri("C:\\BOS-BD-4518-000.dwg.dwf");
        w.Navigate(uri);

        w.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(w_DocumentCompleted);
    }

    void w_DocumentCompleted(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e)
    {
        System.Windows.Forms.WebBrowser w = (System.Windows.Forms.WebBrowser)sender;

        w.Print();
    }

One possible hitch could be that the active x control is not being allowed to be load, does anyone know how to force the control to be initialised.

Does anyone have any ideas about how to solve this or another method of printing an autodesk (.dwf) document

Thanks in advance, SumGuy

+1  A: 

Not really an answer of sorts but a solution if anyone out does want to print a .dwf file. Don't, use the new form .dwfx. This is the new file type Autodesk are switching too and its actually a form of XPS which makes things quite easy. You can load it into a web browser without needing active x OR (this is the better way) use the XPS libraries in visual studio because it can be loaded very simply into an XPS viewer.

The code I eventually used to print the dreaded file is below:

private PrintQueue printQueue;

PrintDialog pDialog = new PrintDialog();
pDialog.PageRangeSelection = PageRangeSelection.AllPages;
pDialog.UserPageRangeEnabled = true;

if (pDialog.ShowDialog() == true)
    PrintSystemJobInfo xpsPrintJob = printQueue.AddJob(v.FileName, v.FilePath, false);

How easy's that??? There are loads of other ways of doing it using XPS. You can basically just use the dwfx file as an XPS document

SumGuy