Printing HTML Files Without Header/Footer Lines Using Microsoft Internet Explorer

Environment: VC++ 7.0

Sometimes you have to print HTML files from your Visual C++ program. If Microsoft’s Internet Explorer is installed, this can be done easily by just calling ShellExecute(hwnd, "print", "my_file.html", 0, 0, SW_SHOW).

Unfortunately, this way you don’t have any control over the header/footer lines that the Web browser prints.

Knowledge base article Q236777 (HOWTO: Change Print Settings for Internet Explorer and WebBrowser Control Programmatically) shows some “undocumented” ways of accessing header/footer values using C++ code. Based on this article, “print_html” has been implemented. By using this module, it is possible to print HTML pages without any header/footer lines (provided that Internet Explorer is installed as the default Internet browser).

Just say #include "print_html.h" at the beginning of your cpp file and add “print_html.cpp” to your workspace. Now it is possible to print HTML files with the following lines of code:

C_PrintHtml ph;
ph.PrintHtml("my_file.html");

You can find “print_html.cpp” and “print_html.h” (as well as a simple example of how to use the module) in the attached zip archive. I used VC++ 7.0 to create the example. The module has been tested with Internet Explorer 6 on Windows NT4 SP6a, Windows 2000 SP2, and Windows XP Professional.

Best regards,
Tilman Kuepper (kuepper@xgraphic.de)

Downloads


Download source – 28 Kb

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read