开发者

Printing from a Windows Service [duplicate]

This question already has answers here: Printing from a .NET Service [closed] (开发者_如何学Python11 answers) Closed 8 years ago.

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.


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


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")


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.


// 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();


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜