开发者

how to print file to a specific Printer

开发者 https://www.devze.com 2023-03-30 01:33 出处:网络
I have developed a windows service with C开发者_如何学Go#. 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,

I have developed a windows service with C开发者_如何学Go#. 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.


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?!


the "Printto" verb needs an argument for the printer name. See this sample in MSDN for more details.


Be aware that printing a PDF unattended violates the Adobe EULA in case of a PDF. Assuming that the .pdf extension is associated with the Adobe PDF Reader (or printer in this scenario...).


there is security around how printing can be handled via a service. if you you are running under a windows account then that service can printer with no UI. I have a print service on a server with a dedicated user account it is printing 1000 of files a day. to over 80 different networked printers.
your service must do and have the following:

  1. it must run as a standard windows users
  2. it must have access to a file structure where the file to be printed can be saved. whatever you are printing must be stored as a file and the file sent to the printer do not forget to do file clean up.
  3. the printers must be connected to just as you would connect to a printer for printing an email
  4. when changing from printer to printer before sending the print job you have to re-set the default printer each
  5. both Telerik and windows word Interop will work for printing.
0

精彩评论

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

关注公众号