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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)