Library code snippets
Printing from the WebBrowser control
There are three methods for doing this.
1. Sending ^p key, using SendKeys, which is not really clean programming :P
2. Using the shell command, and rundll32
Shell "rundll32.exe C:\WINDOWS\SYSTEM\MSHTML.DLL,PrintHTML " & _ "http://www.developerfusion.com"
, vbMinimizedFocus
3. Finally, method 3, which I think is the best method, and uses the built-in
commands for the web-browser. Private Sub PrintUserPage()
'navigate to the page you want
'you can delete this if you want to print the current page
WebBrowser1.Navigate ("http://www.developerfusion.com/")
DoEvents
'print
WebBrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER
'you can change OLECMDEXECOPT_DONTPROMPTUSER to OLECMDEXECOPT_PROMPTUSER if you
wish
End Sub
Related articles
Related discussion
-
Run-time error '91'
by crazyidane (0 replies)
-
Problem handling Redirects with MSXML2.XMLHTTP
by brandoncampbell (2 replies)
-
vbinputbox pauses code while it waits on response. How can I reproduce that?
by brandoncampbell (1 replies)
-
Sending SMS in VB 6
by sirobnole (6 replies)
-
Comboxbox listindex in ActiveX Control
by brandoncampbell (1 replies)
Does anyone knoe how toI specify a filename for the print file when using the webbrowser control to print from VB6?
hy,
i want so set the focus to a frame..
what should i enter instead of <content> ? the frame name?
whats about iframes?
thanks
try this
webBrowser1.ShowPrintDialog()
try this
webBrowser1.ShowPrintDialog()
How can I print from WebBrower using other printer than default printer
That 3rd suggestion of yours worked like a charm! Thank you.
However, now I've managed to show a page in the WebBrowser that has some positioned DIVs. Their positions are changed with a JavaScript function that runs when the page loads.
And then I tried to print that layout and what got printed was the original layout, not the one shown in the WebBrowser. Out of curiosity I right-clicked the page and printed it using the command in the context menu and..... it worked.
Have you ever tried this?
Thank you in advance.
I found the code here would not work for me, because the HTML page had not completed loading before the execWB method was called. I just got error messages. After trying many options, I found the answer was to put the ExecWB command in a sub for the event DownloadComplete.
Private Sub PrintUserPage
Webbrowser1.Navigate ("http://www.yourfavouriteURL.com")
End Sub
Private Sub WebBrowser1DownloadComplete()
WebBrowser1.ExecWB OLECMDIDPRINT, OLECMDEXECOPT_DONTPROMPTUSER
End Sub
This looks like the solution I have been looking for. But unfortunately, the shelling option doesn't print... (not sure why), but how do I code this into a VB.NET web page?
Thanks
With reference to printing the webbrowser content. Sometimes you will have just one frame that you wish to print! So you need to know the frame and set the focus to that frame!
WebBrowser1.Document.parentWindow.<content>.focus
WebBrowser1.ExecWB OLECMDIDPRINT, OLECMDEXECOPTDONTPROMPTUSER
This thread is for discussions of Printing from the WebBrowser control.