Printing HTML Files Without Header/Footer Lines Using Microsoft Internet Explorer
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)

Comments
Printing to network printer
Posted by Legacy on 12/11/2003 12:00amOriginally posted by: waqar
Is there a way to print the html files to the network printer configured for the system.
ReplyAnother solution for user dialog during priting
Posted by Legacy on 11/18/2003 12:00amOriginally posted by: Yaron Shkop
The default printto verb for html files on windows is ofcourse IE.
IE6 however invoke a pop up dialog for the user during printto opperation. It's nice as long as the application is not a server one.. (no UI).
It took me a while to understand that this issue is a browser implementation and I was convinsed so after reading many posts about this in google discussion groups searches.
Most of the people by the way encountered the problem while developing FAX servers using MS FAX services (COM).
The solution is ofcourse to use other browser.
Netscape� Communicator 4.79 is the one that does the job silently as expected (NOT netscape 7.02...), it has to be set as the default browser on the machine.
If you don't want it to be the default browser set the Registry- html files printto only: (HKLM\Software\Classes\htmlfile\shell\printto\) to the values that netscape set them to when it's the default browser. (That way only the printto operation is done through netscape).
The other solution is to use MS-Word as I've already described in my previous post.
Reply
User Dialogs Solution
Posted by Legacy on 11/16/2003 12:00amOriginally posted by: Yaron Shkop
Sorry, but your solution doesn't solve the problem of print dialogs.
The idea was to prevent user dialogs from appearing for server based applications. (No UI!)
The solution is to edit the printto verb inside "Assaociated File Types" to a program that can do it without dialogs.
This is not a perfect solution since the program is MS-WORD.
If you have another software for coverting\printing html without dialogs please add a comment. (A freeware or a built in program in Windows!)
Action:
printto
Application used to ... :
"C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE" /n /dde %1 %2
DDE Message:
[REM _DDE_Minimize][FileOpen("%1")][FilePrintSetup "%2 on p",.DoNotSetAsSysDefault=1][FilePrint 0][DocClose 2][FilePrintSetup ""]
Application:
WinWord
DDE Application not running:
[FileOpen("%1")][FilePrintSetup "%2 on p",.DoNotSetAsSysDefault=1][FilePrint 0][FileExit 2]
Topic:
System
ReplyBatch Print - How can i send a html file to the printer without any print dialog
Posted by Legacy on 07/07/2003 12:00amOriginally posted by: simon soosai
I am trying to send more than 1 files straight to the printer from my html page. How would i do that?
ReplyThis method does not work with IE 6.0
Posted by Legacy on 05/30/2003 12:00amOriginally posted by: Kyselgov E.N.
Reply
Resource leak (handle must be closed)
Posted by Legacy on 05/29/2003 12:00amOriginally posted by: Kyselgov E.N.
Reply
BUG...
Posted by Legacy on 04/19/2003 12:00amOriginally posted by: Xig
ReplyThank god for your soul.
Posted by Legacy on 04/18/2003 12:00amOriginally posted by: Fantom Code
Reply
What about rights?
Posted by Legacy on 02/04/2003 12:00amOriginally posted by: Piotr
I think this solution is good only for Administrator.
ReplyWhat about writing to Registry by user on NT/2000/XP?
Multitasking problem
Posted by Legacy on 12/11/2002 12:00amOriginally posted by: Erik Rydgren
If you have more then one instance of this class printing at the same time then you will probably loose the original settings for header and footer.
ReplyLoading, Please Wait ...