开发者

WebBrowser.Print() wait until complete. .NET

I am using a WebBrowser control in VB.NET and calling the Print() method. I am printing out using a PDF printer and when Print() is called it is not immediately kicked off (it waits until it has completed running code for the entire Sub or block.

I need to make sure the file I am printing too is complete and continue process with this file, therefore, I would like to print on demand and get some status of when the operation is complete. I have tried usign printDocument and process witho开发者_如何学JAVAut luck.

Anyone have any ideas?


Check out the PrintTemplateTeardown event of the underlying unmanaged WebBrowser object. Sometimes that event gets fired multiple times but hopefully this will point you in the right direction. You need to add a reference to Microsoft Internet Controls.

Private Sub Print()
    AddHandler DirectCast(WebBrowser1.ActiveXInstance, SHDocVw.WebBrowser).PrintTemplateTeardown, AddressOf PrintDone
    WebBrowser1.Print()
End Sub
Private Sub PrintDone(ByVal obj As Object)
    Trace.WriteLine("printed")
    RemoveHandler DirectCast(WebBrowser1.ActiveXInstance, SHDocVw.WebBrowser).PrintTemplateTeardown, AddressOf PrintDone
End Sub


Your best bet is to get a handle on your 'printjobscollection' for your default printer and ensure that the jobcount = 0

like this in vb.net:

    Dim intprint As Integer = Nothing

    retry2:
    intprint = GetPrintJobsCollection(printerinuse)
    If Not intprint = 0 Then
        System.Threading.Thread.Sleep(1000)
        GoTo retry2
    End If
    'do what you want to do after print completes here
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜