Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


HTML printing from browser control

Posted on 2003-02-24
Medium Priority
Last Modified: 2010-07-27
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.

Question by:EnricoS
LVL 18

Accepted Solution

Sethi earned 1800 total points
ID: 8007242
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:




Author Comment

ID: 8007409
I believe it is is possible to access print templates from VB
(commercial ActiveX controls are available that wraps the functionality, see http://www.eztools-software.com)

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 . . .
LVL 18

Expert Comment

ID: 8007508
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.

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.


Author Comment

ID: 8007630
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

Expert Comment

ID: 8007690


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.



Author Comment

ID: 8243924
I had hoped to get a lot more people responding . . .

The _excellent_ grading does NOT mean I like your answer    ;)

Expert Comment

ID: 8701864
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.


Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question