Click here to Skip to main content
15,897,718 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
First of all client hit this methoda in this mwthod we call the PrintDocument()
C#
[HttpPost]
 public void Print([FromBody] PrintDetail detail)
        {
            try
            {
                ScreenId = detail.ScreenId;
                objScreen.content = detail.content;
                var t = new Thread(PrintDocument);
                t.SetApartmentState(ApartmentState.STA);
                t.Start();
            }
            catch (Exception ex) { }
        }
		
		
		 [STAThread]
        public void PrintDocument()
        {
            try
            {
                LabelDetails objScreenLabel = new LabelDetails();
                objScreenLabel = GetLabelContainerDetails(ScreenId);
                var htmlPrinter = new WebBrowserPrinter.HtmlPrinter();
                string PrintLabel = "<html><body>" + objScreen.content + "</body></html> ";
                htmlPrinter.PrintToNonDefaultPrinter(// this methods is in another project to print html
                     printerName: objScreenLabel.PrinterName,
                     html: PrintLabel,
                     title: "demo print to non default printer",
                     copies: 1,
                     papername: objScreenLabel.pageName,
                     pageheight: objScreenLabel.pageHeight,
                     pagewidth: objScreenLabel.pageWidth,
                      layout: objScreenLabel.layout
                   );
                System.Windows.Forms.Application.Run();
			}
            catch (Exception ex) { }
		}


It is working fine when application run at visual studio. When we make the installer of this windows service and call this method every goes smoothly we can't get any error but html is not printing .

Please anyone help to solve this problem.

Thanx
Posted
Updated 27-Oct-15 2:40am
v2
Comments
Richard Deeming 27-Oct-15 15:07pm    
Looks like you're trying to display UI from a Windows Service. Windows Services are not interactive processes. You cannot show UI from a Windows Service.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900