I am using a windows service and i want to print a .html page when the service will start. I am using this code and it's printing well. But a print dialog box come, how do i print without the print dialog box?
public void printdoc(string document)
{
Process printjob = new Process();
printjob.StartInfo.FileName = document;
printjob.StartInfo.UseShellExecute = true;
printjob.StartInfo.Verb = "print";
printjob.StartInfo.CreateNoWindow = true;
printjob.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
printjob.Start();
}
Have there any other way to print this without showing the print dialog box.
Thanks in advance, Anup Pal
To add to Vadim's limitation you can set the default printer before printing by using:
And changeing slightly the PrintHtml method with:
Now I don't know how that will fair in a heavy printing environment considering there could be concurrency issues with changeing the default printer a lot. But so far this is the best I came up with to fix this limitation.
In windows service the Microsoft web browser control is not working. I had used that code it's working fine in windows application but when i am using within a windows service then the program getting stuck in this line
axWebBrowser1.Navigate(@"C:\mydoc.html", ref empty, ref empty, ref empty, ref empty);
thanks for reply, Anup Pal
Here's the Holy Grail.
Taking advantage of StaTaskScheduler (taken from Parallel Extension Extras (release on Code Gallery)).
Features: waits for the printing completion, doesn't show print settings, hopefully reliable.
Limitations: requires C# 4.0, uses default printer, doesn't allow to change print template