Printing HTML in VB .NET

G

Guest

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
 
G

Guest

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.
 
R

Rick

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top