Printing WebPages from VB.net

  • Thread starter Thread starter Peter
  • Start date Start date
P

Peter

I have a couple pages on our intranet that I want to print on a
regular basis. The conent is dynamic, and so I want to take
snapshots, and send these jobs directly to a printer on the network.

Has anyone done this before? I'm looking for some sample code.

Thanks,

Peter
 
I have code that achieves this in VB6 if you wish to take a look at it - I
will dig it out. I did ave problems getting this to work due to the
Microsoft security patches, but some kind soul e-mailed me the solution
months after my original post. It may be a few hours before I get the chance
to search for the code.

Best wishes

Paul Bromley
 
* (e-mail address removed) (Peter) scripsit:
I have a couple pages on our intranet that I want to print on a
regular basis. The conent is dynamic, and so I want to take
snapshots, and send these jobs directly to a printer on the network.

2 solutions:

\\\
Dim p As New System.Diagnostics.ProcessStartInfo()
p.Verb = "print"
p.WindowStyle = ProcessWindowStyle.Hidden
p.FileName = "C:\filename.htm"
p.UseShellExecute = True
System.Diagnostics.Process.Start(p)
///

- or -

<URL:http://groups.google.de/groups?selm=#[email protected]>
 
Hi Peter,

Hope this helps. It took me quite a time to get the answer initially, and
then my code stopped working after 5.5 of Internet Explorer, but thankfully
due to some kind soul who e-mailed me a couple of months after I put out a
query, the problem was resolved - by sending 0s in the parmaters rather than
null strings as initially recommended by the Microsoft dcoumentation.

I have quickly tried the coe in VB.Net and it seems to work for me.

Best wishes

Paul Bromley

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim sPrintEm As Integer = 1
Dim eQuery As SHDocVw.OLECMDF
eQuery = AxWebBrowser1.QueryStatusWB(SHDocVw.OLECMDID.OLECMDID_PRINT)
If Err.Number = 0 Then
If eQuery And SHDocVw.OLECMDF.OLECMDF_ENABLED Then
Select Case sPrintEm
Case "1"
AxWebBrowser1.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT,
SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_PROMPTUSER, 0, 0)
Case "2"
AxWebBrowser1.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT,
SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, 0, 0)
End Select
Else
MsgBox("The Print command is currently disabled.")
End If
End If
End Sub
 
Both of these solutions worked great. For us less technical gurus, I
had to 1. Add Reference - Microsoft.mshtml
2. Open a form and add in a com object named: Microsoft Web Browser

The rest of the code worked sweet! Thanks!


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
AxWebBrowser1.Navigate("http://www.google.com")

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim sPrintEm As Integer = 1
Dim eQuery As SHDocVw.OLECMDF
eQuery = AxWebBrowser1.QueryStatusWB(SHDocVw.OLECMDID.OLECMDID_PRINT)
If Err.Number = 0 Then
If eQuery And SHDocVw.OLECMDF.OLECMDF_ENABLED Then
Select Case sPrintEm
Case "1"

AxWebBrowser1.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT,
SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_PROMPTUSER, 0, 0)
Case "2"

AxWebBrowser1.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT,
SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, 0, 0)
End Select
Else
MsgBox("The Print command is currently disabled.")
End If
End If
End Sub

The other code printed anything locally without issue! You guys rock!
Thanks!
 
Sorry Peter, I should have mentioned adding the reference and the
web-browser control. I think that I had assumed that you were navigating to
the Intranet page with a Web browser anyway, hence you had the control in
your application anyway. Glad I can help - I have had a lot of help myself
here in the past and am by no means an expert.

Best wishes

Paul Bromley
 
Back
Top