468,505 Members | 1,900 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,505 developers. It's quick & easy.

Printing HTML in VB .NET

What i am trying to accomplish is programatically creating Invoices and then
Printing them out. I don't really need to "View" them before they print.

How I am trying to do this is I have created a "Template" of the invoice in
HTML. Througout the text of the HTML are keywords or variables. I load this
in .NET with a streamreader, edit the string to find/replace the keyword
(variable) with the value (example: in the string are the characters
"INVNUM". So, i find "INVNUM" and replace it with "123456", or whatever the
invoice number is).

When it is done, i use a streamwriter to create a "Text" file with the HTML
Code.

Then I use a WebBrowser class to Load (myWebBrowser.URL = New
URI("Path\Of\HTMLFile.HTML")

and create an Event Handler (myWebBrowser.DocumentCompleted) to print the
file when it is done loading. WebBroswer (myWebBrowser.Print).

This works perfect if there is only one invoice. However, i use a loop
(either for/next or while) to iterate through a database, and create all the
invoices. Instead of printing after each one, it seems like the
myWebBrowser.DocumentCompleted event is not raised until the entire routine
(thus All of the invoices) are loaded.

If I have a couple html files, it still works, however as soon as i have
more than a few, the program crashes.

Any suggestions on how to accomplish this? Either have the html file sent
to the printer after each one is created (instead of at the end) or even
another method? I'm not married to HTML, but this seemd the easiest way to
create/edit on the fly and make it pretty as well.

Thank you
MATT
Apr 18 '07 #1
2 8464
=?Utf-8?B?TUFUVA==?= <MA**@discussions.microsoft.comwrote in
news:93**********************************@microsof t.com:
This works perfect if there is only one invoice. However, i use a
loop (either for/next or while) to iterate through a database, and
create all the invoices. Instead of printing after each one, it seems
like the myWebBrowser.DocumentCompleted event is not raised until the
entire routine (thus All of the invoices) are loaded
I believe each instance of the web browser control spawns an IE session
under the covers... so it's not all that "efficient". It's probably best to
load documents in series (one by one) rather than in parallel.

There are a couple 3rd party components that are designed to print HTML...
but I'm not sure what rendering engine these use, so I'm not sure what the
quality is like. These components might be worth a look if you need higher
performance.
Apr 18 '07 #2
Matt,

Could you save the html into a temp file and then call
Process.Start(Temp.html,"print")?

I think this may instantiate IE for each print job, but it will close
afterward.

You might also try to WebBrowser.Navigate("about:blank") +
Application.DoEvents between invoices and see if that helps.

Rick
"MATT" <MA**@discussions.microsoft.comwrote in message
news:93**********************************@microsof t.com...
What i am trying to accomplish is programatically creating Invoices and
then
Printing them out. I don't really need to "View" them before they print.

How I am trying to do this is I have created a "Template" of the invoice
in
HTML. Througout the text of the HTML are keywords or variables. I load
this
in .NET with a streamreader, edit the string to find/replace the keyword
(variable) with the value (example: in the string are the characters
"INVNUM". So, i find "INVNUM" and replace it with "123456", or whatever
the
invoice number is).

When it is done, i use a streamwriter to create a "Text" file with the
HTML
Code.

Then I use a WebBrowser class to Load (myWebBrowser.URL = New
URI("Path\Of\HTMLFile.HTML")

and create an Event Handler (myWebBrowser.DocumentCompleted) to print the
file when it is done loading. WebBroswer (myWebBrowser.Print).

This works perfect if there is only one invoice. However, i use a loop
(either for/next or while) to iterate through a database, and create all
the
invoices. Instead of printing after each one, it seems like the
myWebBrowser.DocumentCompleted event is not raised until the entire
routine
(thus All of the invoices) are loaded.

If I have a couple html files, it still works, however as soon as i have
more than a few, the program crashes.

Any suggestions on how to accomplish this? Either have the html file sent
to the printer after each one is created (instead of at the end) or even
another method? I'm not married to HTML, but this seemd the easiest way
to
create/edit on the fly and make it pretty as well.

Thank you
MATT

Apr 18 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Mark Preston | last post: by
7 posts views Thread by Dennis C. Drumm | last post: by
3 posts views Thread by Ahmad Abu-Raddad | last post: by
7 posts views Thread by Amirallia | last post: by
2 posts views Thread by Jurjen de Groot | last post: by
12 posts views Thread by Alex Clark | last post: by
4 posts views Thread by Lucas Ponzo | last post: by
reply views Thread by NPC403 | last post: by
3 posts views Thread by gieforce | last post: by
reply views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.