I want to print HTML from a C # web service. Management through a web browser is unnecessary, it does not work properly in a service environment and does not work properly in a system with very severe security restrictions. Is there any free .NET library that will support printing a basic HTML page? Here is the code that I have that does not work properly.
public void PrintThing(string document) { if (Thread.CurrentThread.GetApartmentState() != ApartmentState.STA) { Thread thread = new Thread((ThreadStart) delegate { PrintDocument(document); }); thread.SetApartmentState(ApartmentState.STA); thread.Start(); } else { PrintDocument(document); } } protected void PrintDocument(string document) { WebBrowser browser = new WebBrowser(); browser.DocumentText = document; while (browser.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); } browser.Print(); }
This works great when called from threads like a user interface, but nothing happens when called from a thread like a service. Changing Print() to ShowPrintPreviewDialog() results in the following IE script error:
Error: dialogArguments.___IE_PrintType is null or not an object.
URL: res://ieframe.dll/preview.dlg
And a small empty preview dialog appears.
html c # web-services printing
Chris Marasti-Georg Aug 01 '08 at 18:33 2008-08-01 18:33
source share