HTML printing from browser control

My (Visual Basic 6) application uses IE's webbrowser control (embedded) to render/view HTML reports. I am not happy with the printing support from the control. I have the following specific problems:
1) THEAD/TFOOT tags does not repeat on the next page when a table is split accross printed pages (as the HTML specification says it should)
2) Lines are sometimes lost at page breaks - this depends on the margin settings & printer driver
3) Very tricky to set page orientation/margins etc. from VB code before using the ExecWB...PRINT method of the browser to do the actual printing (especially if you have to cater for different IE versions).

I am looking for something that will help with all three of the problems above . . .

These are some of the things I am considering:
a) Convert the HTML to some other format (PDF/Rich Text/Postscript) using some conversion tool (?) and then printing the "result"
   --> which format?, which converter?
   --> does these formats (and the tools that goes with them) fix my problems
       ie. does the PDF specification allow for tables with column headers, and the automatic re-print of headers on the "next" page
       how tricky is it to print these formats (from VB code), can one get at the page-setup properties from code (will probably depend on what tool does the actual printing)
   --> I get the feeling that this option will introduce more _new_ problems than it will solve

b) IE Print templates
   --> this one promises a lot but the samples & documentation (MSDN) is somewhat vague - seriously steep learning-curve to try and understand the technology (and all that just to determine if it may be the answer to my problem)
   --> any experts on this subject that can say yea or nea?

c) code my own parser & print logic (we use a very small subset of HTML, mainly <TABLE> stuff)

Any other options that anyone can think of ?

I am cross-posting this one to the HTML and Browser Issues groups

I doubt anyone will give a complete answer, will distribute points between most helfull comments.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I created my own HTML reporting just three weeks back and was asking the same questions that you are asking now. To summarize the answer for your question on printing HTML reports in VB - "You will always face problems with it and it cant be exactly the way you want it to be." Now I will answer your problem step by step:

1. Thead and Tfoot donot do the functionality as specified in HTML standards becuase they are not completely supported by most of the browsers including IE. IE supports Thead only for display and not for printing.

2. You will always face problems in setting the margins, portratit/landscape formats and other ascpet of printing. This is Becuase Microsoft is very direct in admitting that IE was made for display purposes and its utility for printing was never given a priority. Its lately that its printing utility is being given priority and functionalities like Print templates etc have been exposed.

3. IE print templates can only be created through C++. So no hope for VB programmers at the moment.

4. You do whatever you can do to manipulate your HTML code either through Tables or through any other pareser, the printing capabilities of IE will haunt you. I went to an extent of learning CSS and also implemented it with my HTML reports, but CSS also couldn't control IE's printing functionlities.

5. Using the @Print and @Media tags in HTML 4.0 will not help you completely becuase again the browser would disappoint you as all these functionalities are not completely supported by every browser.

To summarize again, you can create better reports through HTML in VB but you cant print them the way you want. Here are a few links if you still want to explore net:


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
EnricoSAuthor Commented:
I believe it is is possible to access print templates from VB
(commercial ActiveX controls are available that wraps the functionality, see

It sounds as if you got _some_ joy from using @Print and @Media (I have not heard of this before, will have a look)
My code uses Internet Explorer's browser control, so I am not concerned with the functionality of "other" browsers - if I can get it to work on IE then I'll be happy . . .
If some Commercial ActiveX control is providing you Print Templates functionality then it may be possible. My comment clearly stated that:- "IE print templates can only be created through C++". If you want to go for Coomercial options and are ready to spend mony for printing purposes then google is there for you. You will get umpteen no. of componenets for this purpose.

If you have gone through the links I have provided you and if you go through the comment I have posted again then you will see that I am pointing my finger to IE again and again considering it to be the most popular one and not at any other browser.
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

EnricoSAuthor Commented:
Thnx Sethi,

The control mentioned will only give me access to print templates - I do no (yet) know if templates is the answer to my problems (I know too little about the technology)

I spent some time looking at commercial tools - none of which claims to be able to solve all my problems - most of them leverages the IE print engine, which means that the problems with THEAD/TFOOT will still be there.

I'll even be willing to switch browsers if the other browser has a component that can be embedded on a VB form, and has a print engine that handles my specific problems better


when I had to do this, I found the best way was to save the HTML document and open it in a MS Word object. This tends to print a lot better, but I know that others have had problems doing it this way. For example, list items do not always appears as expected.

If you want some code samples let me know and I'll dig some up.


EnricoSAuthor Commented:
I had hoped to get a lot more people responding . . .

The _excellent_ grading does NOT mean I like your answer    ;)
The answer to problem #1 is to add a style attribute to the thead tag as follow:

<THEAD STYLE='display: table-header-group'>

This will cause the contents of thead to repeat on each printed page.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.