Home > DeveloperSection > Forums > How do I print an HTML document from a web service?
alexander sabato
alexander sabato

Total Post:4

Points:28
Posted on    February-04-2013 2:11 AM

 C# C# 
Ratings:


 2 Reply(s)
 1951  View(s)
Rate this:

Hi Expert!

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

Thanks in advance



AVADHESH PATEL

Total Post:604

Points:4228
Posted on    February-04-2013 5:52 AM

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.


Dinesh Tummala
Dinesh Tummala

Total Post:1

Points:7
Posted on    December-12-2016 9:43 AM

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

Don't want to miss updates? Please click the below button!

Follow MindStick