HOW DO I PRINT AN HTML DOCUMENT FROM A WEB SERVICE?

alexander sabato

Total Post:4

Points:28
Posted by  alexander sabato
C# 
C#
 2144  View(s)
Ratings:
Rate this:

Hi Expert!

How to print HTML document using command line and C#.

Thanks in advance

  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: How do I print an HTML document from a web service?

    Hi Alexander Sabato!

    Run this command into command prompt

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

    If you are using C#, than used line of code as below

    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 """ + FilePath + @"""";
        printProcess.Start();
    }

    Note: Here "FilePath", represent path of document which you want to print.

  1. Dinesh Tummala

    Post:1

    Points:7
    Re: How do I print an HTML document from a web service?

    I have tried with the above code but it will ask to Click the Print button through dialog box.


    How can i avoid this Please help me.

    I will try with the below code snippet.But it will not work.

    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 """ + document + @"""";
                  
                 printProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

                 printProcess.Start();
            }

    When i run the above code nothing printed.Please help me with this.

    Thanks in Advance

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!