How do I print an HTML document from a web service?

You can print from the command line using the following:

rundll32.exe %WINDIR%\System32\mshtml.dll,PrintHTML "%1"

Where %1 is the file path of the HTML file to be printed.

If you don't need to print from memory (or can afford to write to the disk in a temp file) you can use:

using (Process printProcess = new Process())
{
    string systemPath = Environment.GetFolderPath(Environment.SpecialFolder.System);
    printProcess.StartInfo.FileName = systemPath + @"\rundll32.exe";
    printProcess.StartInfo.Arguments = systemPath + @"\mshtml.dll,PrintHTML """ + fileToPrint + @"""";
    printProcess.Start();
}

N.B. This only works on Windows 2000 and above I think.


I know that Visual Studio itself (at least in 2003 version) references the IE dll directly to render the "Design View".

It may be worth looking into that.

Otherwise, I can't think of anything beyond the Web Browser control.