Printing from a Windows Service [duplicate]

南楼画角 提交于 2020-01-29 23:30:13

问题


How can I printing a document on a specific printer from a Windows-Service without the need of any user-interaction?

A string, or a text-file. Maybe Crystalreport?

Thanks.


回答1:


The point is not how to print from a windows service or from an application, if you don't want any user interaction to be required you have to specify all print parameters without any need to show a print dialog ( which you can't because a windows service has no access to the UI ).

see here: http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx




回答2:


Try to create a Multithreaded Services. Once you create the service with Admin previledges, it won't get interfere by users. (Actually I didn't understantpurpose of "without the need of any user-interaction")




回答3:


There is another discussion on this using crystal reports: Print without Printer selection dialog

And here's another one for printing html Print html document from Windows Service without print dialog

Hopefully, they'll get you started in the right direction.




回答4:


// Class that handles printing
class MyPrintDocument : PrintDocument
    {
       //...
    }

when you want to print:

        // Create an instance of your printer class
        MyPrintDocument printer = new MyPrintDocument();

        // Set StandardPrintController so status dialog won't appear
        printer.PrintController = new StandardPrintController();



回答5:


To 'silently' print from a Windows Service you should utilise Win32 GDI API.

If you are developing a Microsoft .NET application, you can use Platform Invocation Services (PInvoke) to call the Win32 GDI APIs to print. Heres a nice PInvoke tutorial. Take a look here for Win32 GDI methods etc.

Here is more information and an example regarding printing from a windows service from Microsoft's DSUI team... take a look



来源:https://stackoverflow.com/questions/4945177/printing-from-a-windows-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!