Search code examples
c#.netprintingwindows-services

how to print file to a specific Printer


I have developed a windows service with C#. Now I am searching a way, that it can print a specific file (could be a TIFF, PDF, HTML, MHT or Text) to a specific printer. The problem is, when I do it with a Process and print as verb, how can I set the specific printer? And is the way with using a Process also possible in a Windows Service? - It shouldn't show a window.


Solution

  • This proposed approach is likely to fail in my view. Using the shell verbs to print is going to invoke the associated applications to perform the printing. For many of these file types, this will result in UI being displayed which will fail in a service.

    All the file types you mention can be printed direct from your service without recourse to other applications. It will require more coding but I believe it is the most viable solution for a service.

    Alternatively you could do this from a standard app running on an interactive desktop. That should work fine and I presume you will be in control of the hardware and software configuration of the machines that run this code. Otherwise using shell verbs would be a terribly fragile and brittle approach-who knows what file associations are in place on a random customer's machine?!