472,995 Members | 1,537 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 8972
=?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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Mark Preston | last post by:
Admission first - I don't actually have a problem here but have noticed that a lot of people have been asking similar questions and getting very varied answers. What I've done is to sort of...
7
by: Dennis C. Drumm | last post by:
I was wondering if someone could suggest were/how I could get started with setting up printing of a collection of text that includes tables from a grid and other supporting information about the...
3
by: Ahmad Abu-Raddad | last post by:
Hey Guys, Does anyone knows of a way to print HTML source directly to the printer (Server Side)?. I tried the PrintDocument class and the e.Graphics.DrawString and e.Graphics.DrawImage() but...
1
by: Raymond Du | last post by:
Hi, I have serveral web forms used by users, these users often use IE browser print function to print out the form, the problems I have is what users see on the screen is usually different from...
7
by: Amirallia | last post by:
Hello! I have a wecontrol table in a page, this table has a number of variable rows depending of the choice of the user. But when the table has a large number of rows, the printing of the page...
2
by: Jurjen de Groot | last post by:
I'm about to start a new ASP.NET application, this application will generate several types of documents (PDF HTML XML-DOC) wich have to be printed at the client-side... (probably on different...
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...
4
by: Lucas Ponzo | last post by:
Hi All, I have an ASP.NET 2.0 app. The users access the pages, uniquely via pocket pc ... I need to print a page. But I need that the page print on a printer installed on the web server...
8
by: Neo Geshel | last post by:
Greetings. BACKGROUND: My sites are pure XHTML 1.1 with CSS 2.1 for markup. My pages are delivered as application/xhtml+xml for all non-MS web clients, and as text/xml for all MS web...
0
by: nikhilgargi | last post by:
Requirement: I need to provide printing capability in a C# desktop application that I am developing The documents that need to be printed can be in Rich Text Format (RTF) or HTML. Custom...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

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.