【发布时间】:2011-02-09 13:00:35
【问题描述】:
如何在不需要任何用户交互的情况下通过 Windows 服务在特定打印机上打印文档?
字符串或文本文件。也许水晶报告?
谢谢。
【问题讨论】:
标签: c# printing windows-services
如何在不需要任何用户交互的情况下通过 Windows 服务在特定打印机上打印文档?
字符串或文本文件。也许水晶报告?
谢谢。
【问题讨论】:
标签: c# printing windows-services
关键不是如何从 Windows 服务或应用程序打印,如果您不希望需要任何用户交互,则必须指定所有打印参数,而无需显示打印对话框(您可以'不是因为 Windows 服务无法访问 UI)。
请看这里:http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx
【讨论】:
尝试创建多线程服务。一旦您创建了具有管理员权限的服务,它就不会受到用户的干扰。 (其实我并没有理解“不需要任何用户交互”的目的)
【讨论】:
使用水晶报告对此还有另一个讨论: Print without Printer selection dialog
还有一个用于打印 html Print html document from Windows Service without print dialog
希望他们能让你朝着正确的方向开始。
【讨论】:
// Class that handles printing
class MyPrintDocument : PrintDocument
{
//...
}
当您想打印时:
// Create an instance of your printer class
MyPrintDocument printer = new MyPrintDocument();
// Set StandardPrintController so status dialog won't appear
printer.PrintController = new StandardPrintController();
【讨论】:
要从 Windows 服务“静默”打印,您应该使用 Win32 GDI API。
如果您正在开发 Microsoft .NET 应用程序,您可以使用平台调用服务 (PInvoke) 调用 Win32 GDI API 进行打印。 Heres a nice PInvoke tutorial。 Take a look here for Win32 GDI methods etc.
这里是微软 DSUI 团队关于从 Windows 服务打印的更多信息和示例...take a look
【讨论】: