Hello Jan!
I've done this already!
The result is:
08.04.2009 17:10:04:294 ;TRACE ;IFCPrinter.StaticPrintReportLocal on printer "infotec IS 2122 PCL 6": CASE 1
08.04.2009 17:10:04:373 ;ERROR ;System.ComponentModel.Win32Exception: The handle is invalid
at Stimulsoft.Base.StiExceptionProvider.Show(Exception exception)
at Stimulsoft.Report.Print.StiPrintProvider.Print(StiReport report, Boolean showPrintDialog, Int32 fromPage, Int32 toPage, Int16 copies, PrinterSettings printerSettings)
at Stimulsoft.Report.StiReport.Print(Boolean showPrintDialog, Int32 fromPage, Int32 toPage, Int16 copies, PrinterSettings printerSettings)
at Stimulsoft.Report.StiReport.Print(Boolean showPrintDialog, PrinterSettings printerSettings)
at Stimulsoft.Report.StiReport.Print(PrinterSettings printerSettings)
bevore done this, result was:
System.InvalidOperationException: Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation.
Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at System.Windows.Forms.Form.ShowDialog()
at Stimulsoft.Base.StiExceptionProvider.Show(Exception exception)
at Stimulsoft.Report.Print.StiPrintProvider.Print(StiReport report, Boolean showPrintDialog, Int32 fromPage, Int32 toPage, Int16 copies, PrinterSettings printerSettings)
at Stimulsoft.Report.StiReport.Print(Boolean showPrintDialog, Int32 fromPage, Int32 toPage, Int16 copies, PrinterSettings printerSettings)
at Stimulsoft.Report.StiReport.Print(Boolean showPrintDialog, PrinterSettings printerSettings)
at Stimulsoft.Report.StiReport.Print(PrinterSettings printerSettings)
I's the same on all printers
Now I've, probably, really bad news. There are some issues in Windows Server 2008 what makes life difficult.
I wrote other very simple service, which only prints some lines of text with standart .net methods
Code: Select all
private void PrintMethod()
{
printDocument1 = new PrintDocument();
stringToPrint = "First line\n\rSecond line\r\nThird line";
Font = new Font("Arial", 10);
printDocument1.PrintPage += printDocument1_PrintPage;
printDocument1.DocumentName = "Test Document from Service";
PrinterSettings iPrinterSettings = new PrinterSettings();
iPrinterSettings.PrinterName = "HP Color LaserJet 3800";// "infotec IS 2122 PCL 6";
printDocument1.DefaultPageSettings.PrinterSettings = iPrinterSettings;
printDocument1.PrinterSettings = iPrinterSettings;
printDocument1.Print();
}
PrintDocument printDocument1 = new PrintDocument();
string stringToPrint = "First line\n\rSecond line\r\nThird line";
Font Font = new Font("Arial", 10);
private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
{
int charactersOnPage = 0;
int linesPerPage = 0;
// Sets the value of charactersOnPage to the number of characters
// of stringToPrint that will fit within the bounds of the page.
e.Graphics.MeasureString(stringToPrint, this.Font,
e.MarginBounds.Size, StringFormat.GenericTypographic,
out charactersOnPage, out linesPerPage);
// Draws the string within the bounds of the page
e.Graphics.DrawString(stringToPrint, this.Font, Brushes.Black,
e.MarginBounds, StringFormat.GenericTypographic);
// Remove the portion of the string that has been printed.
stringToPrint = stringToPrint.Substring(charactersOnPage);
// Check to see if more pages are to be printed.
e.HasMorePages = (stringToPrint.Length > 0);
}
The throws also an Exception:
08.04.2009 19:08:20:638 ;ERROR ;The handle is invalid
08.04.2009 19:08:20:685 ;ERROR ;at System.Drawing.Printing.StandardPrintController.OnStartPrint(PrintDocument document, PrintEventArgs e)
at System.Windows.Forms.PrintControllerWithStatusDialog.OnStartPrint(PrintDocument document, PrintEventArgs e)
at System.Drawing.Printing.PrintController.Print(PrintDocument document)
at System.Drawing.Printing.PrintDocument.Print()
at DE.KLD.IDS.FCTest.FCTestService.RunningMethod() in D:\TFSProjects\FCServer\Main\IdsBasisPgm\ClassLibrary1\FCTestService.cs:line 139
at DE.KLD.IDS.FCTest.FCTestService.Work() in D:\TFSProjects\FCServer\Main\IdsBasisPgm\ClassLibrary1\FCTestService.cs:line 105
The problem with StiExceptionProvider was, it does cut the call stack and it was impossible to identificate the source of exception.
The service cant' print for some reasons, but a standalone console program can.
Now it's the question, how to deal with this problem. There are some search result about this issue and it looks like some products implements a workarounds, but I've not found, what the workarounds are.
Thanks!