【问题标题】:Printing from a Windows Service [duplicate]从 Windows 服务打印 [重复]
【发布时间】:2011-02-09 13:00:35
【问题描述】:

如何在不需要任何用户交互的情况下通过 Windows 服务在特定打印机上打印文档?

字符串或文本文件。也许水晶报告?

谢谢。

【问题讨论】:

    标签: c# printing windows-services


    【解决方案1】:

    关键不是如何从 Windows 服务或应用程序打印,如果您不希望需要任何用户交互,则必须指定所有打印参数,而无需显示打印对话框(您可以'不是因为 Windows 服务无法访问 UI)。

    请看这里:http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx

    【讨论】:

    • 很遗憾,官方不推荐从 Windows 服务打印:Discussion.
    【解决方案2】:

    尝试创建多线程服务。一旦您创建了具有管理员权限的服务,它就不会受到用户的干扰。 (其实我并没有理解“不需要任何用户交互”的目的)

    【讨论】:

    • @david 好吧,鉴于他确实承认他不理解问题的那一部分,因此说他的答案可能不正确并不是不公平的。你的评论有点苛刻。 @pawan,我认为OP想要一种方法,该方法可以通过用户未启动的某些事件或其他触发器以编程方式自动打印。因此,正如大卫指出的那样,在这种情况下,服务是否是多线程的无关紧要。
    • @David,是的,我不明白这个问题,但我试图给出我的水平最好的答案。我还在学习......别担心,thatx 批评我。总有一天我会比你回答得更好。 @joe...谢谢,下次我在回答之前尝试理解问题。
    【解决方案3】:

    使用水晶报告对此还有另一个讨论: Print without Printer selection dialog

    还有一个用于打印 html Print html document from Windows Service without print dialog

    希望他们能让你朝着正确的方向开始。

    【讨论】:

      【解决方案4】:
      // 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();
      

      【讨论】:

        【解决方案5】:

        要从 Windows 服务“静默”打印,您应该使用 Win32 GDI API

        如果您正在开发 Microsoft .NET 应用程序,您可以使用平台调用服务 (PInvoke) 调用 Win32 GDI API 进行打印。 Heres a nice PInvoke tutorialTake a look here for Win32 GDI methods etc.

        这里是微软 DSUI 团队关于从 Windows 服务打印的更多信息和示例...take a look

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2010-11-03
          • 1970-01-01
          • 1970-01-01
          • 2011-05-09
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多