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

后端 未结 7 1442
夕颜
夕颜 2020-12-13 22:46

I want to print HTML from a C# web service. The web browser control is overkill, and does not function well in a service environment, nor does it function well on a system

7条回答
  •  既然无缘
    2020-12-13 23:28

    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.

提交回复
热议问题