473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Webbrowser printing

First, please be gently. I am fairly new to the programming world (1.5
years with some expermentation prior to).

I have been working on a project that has to print HTML pages with
graphics in a unattended automated fashion. I have a webbrowser that
is created with code but not seen. I found the below code on the
internet. It creates a webbrowser, and specifies the URL, which
navigates the webbrowser to the page. When the document is finished
loading, the second sub kicks in to print it. This has worked great up
to this point. Now I am know trying to catch errors/exceptions with no
luck. The code seems to just keep going. Examples of exceptions to
catch
1.) Pass a network URL that can not be reached. Currently the program
accepts the url, I assume 404 file not found problably loads and
completes, which kicks of the PrintDocument sub. No errors with the
current code.
2.) Pass a URL that can be reached and loaded properly. The
PrintDocument sub is run, but say a printer error occurs. No errors
with the current code.

Anybody with any ideas on how to catch errors?

Should I be using a different method for printing? If so, sample code
would be appreciated. I have seen other code to create a HTML doc to
load and then print with the EXECWB command, but have had not luck
getting it to work.

************************************************** ***********************
Public Sub LoadBrowser(ByVal strFileURL As String)
Try
'Create a WebBrowser instance.
Dim webBrowserForPrinting As New WebBrowser()

'PrintInProgress = True
Printing = "True"

'Add an event handler that prints the document after it
loads.
AddHandler webBrowserForPrinting.DocumentCompleted, New _
WebBrowserDocumentCompletedEventHandler(AddressOf
PrintDocument)

'Set the Url property to load the document.
webBrowserForPrinting.Url = New Uri(strFileURL)

Catch ex As Exception
Dim strErrorMsg As String
strErrorMsg = "Error in LoadBrowser-PrintHTML." & vbCrLf &
ex.ToString
Printing = "Error in LoadBrowser-PrintHTML." & vbCrLf &
ex.Message
'add LogMessage here
MessageBox.Show(strErrorMsg)
Dim clsEmail As New Email
clsEmail.EmailSend(strErrorEmailName & strEmailDomian,
SystemInformation.ComputerName & strEmailDomian, _
"An Error Message From " &
Application.ProductName, strErrorMsg)

End Try

End Sub
************************************************** ***********************
Public Sub PrintDocument(ByVal sender As Object, _
ByVal e As WebBrowserDocumentCompletedEventArgs)

Try
If Microsoft.VisualBasic.Left(Printing, 5) = "Error" Then

Else
Dim webBrowserForPrinting As WebBrowser = CType(sender,
WebBrowser)

'Print the document now that it is fully loaded.
webBrowserForPrinting.Print()

'Dispose the WebBrowser now that the task is complete.
webBrowserForPrinting.Dispose()

Printing = "False"
End If

Catch ex As Exception
Dim strErrorMsg As String
strErrorMsg = "Error in PrintDocument-PrintHTML." & vbCrLf
& ex.ToString
Printing = "Error in PrintDocument-PrintHTML." & vbCrLf &
ex.Message
'add LogMessage here
MessageBox.Show(strErrorMsg)
Dim clsEmail As New Email
clsEmail.EmailSend(strErrorEmailName & strEmailDomian,
SystemInformation.ComputerName & strEmailDomian, _
"An Error Message From " &
Application.ProductName, strErrorMsg)
End Try

End Sub
************************************************** ***********************

Feb 14 '06 #1
1 2857
Help!
Anybody??
Is there a better group to post this question??

Feb 15 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Noozer | last post by:
I've got a WebBrowser control (AxBrowse - VCMAXB.DLL) and I'm having a few difficulties with it. Just looking for a few pointers, not whole solutions here. I've tried looking at the MSDN help files...
0
by: Carl Manson | last post by:
Hi All, I am writing a complex print job solution that requires the printing of many HTML documents in an exactly defined order. Our application uses the IE WebBrowser control to render the...
5
by: John Bowman | last post by:
Hi, I've been reading through the threads on using the WebBrowser control in C# app's and how to print it's contents. I've got that much working. However, the big problem is I can't figure out...
2
by: Chris Bingham | last post by:
Hi everyone, Does anyone know how to fix the paper orientation depending on the paper size used when printing with the WebBrowser control please? What I've got is a HTML file, containing 1 big...
1
by: eskildb | last post by:
First, please be gently. I am fairly new to the programming world (1.5 years with some expermentation prior to). I have been working on a project that has to print HTML pages with graphics in a...
12
by: Alex Clark | last post by:
Greetings, (.NET 2.0, WinXP Pro/Server 2003, IE6 with latest service packs). I've decided to take advantage of the layout characteristics of HTML documents to simplify my printing tasks, but...
2
by: johnb41 | last post by:
I'm using .NET 2.0. My form is displaying the webbrowser control, which is displaying some HTML text. When printing with webbrowser.print(), my printout includes the header and footer. How...
11
by: Webbert | last post by:
I am trying to display XML in a WebBrowser Control. I receive a data feed of XML and am trying to inject it into the control. I have not been successful in doing so. The only solution I have...
1
by: Tim Sprout | last post by:
I want to call Page Setup to set default printer and page size and orientation before batch printing pdf's silently from WebBrowser controls. I can print silently using DDE (the NDde library) or...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.