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

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 […]

Written By
CodeGuru Staff
CodeGuru Staff
Feb 7, 2003
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

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

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.