Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing from a .NET Service [closed]

Tags:

I am working on a project right now that involves receiving a message from another application, formatting the contents of that message, and sending it to a printer. The technology of choice is C# windows service. The output could be called a report, I suppose, but a reporting engine is not necessary. A simple templating engine, like StringTemplate, or even XSLT outputting HTML would be fine. The problem I'm having is finding a free way to print this kind of output from a service. Since it seems that it will work, I'm working on a prototype using Microsoft's RDLC, populating a local report and then rendering it as an image to a memory stream, which I will then print. Issues with that are:

  • Multi-page printing will be a big headache.
  • Still have to use PrintDocument to print the memory stream, which is unsupported in a Windows Service (though it may work - haven't gotten that far with the prototype yet)
  • If the data coming across changes, I have to change the dataset and the class that the data is being deserialized into. bad bad bad.

Has anyone had to do anything remotely like this? Any advice? I already posted a question about printing HTML without user input, and after wasting about 3 days on that, I have come to the conclusion that it cannot be done, at least not with any freely available tool.

All help is appreciated.

EDIT: We are on version 2.0 of the .NET framework.

like image 815
Chris Marasti-Georg Avatar asked Aug 11 '08 17:08

Chris Marasti-Georg


People also ask

Why can I not print from my browser?

The common reasons if the web browsers are not printing could be due to: Conflicts with Add-ons. Incompatible driver Components. Incorrect Printer software settings.

Can a Windows service print?

The print document class provided by . NET is capable of printing inside a Windows Service. The benefit of using the print document class is that it gives some control of printing and settings. It exposes an event which can be consumed to change printing settings.

Why can't I print from Internet Windows 10?

This issue may arise due to driver conflicts or change in printer settings and as an initial troubleshooting step, run printer troubleshooter and check if it helps to resolve the issue.


2 Answers

Trust me, you will spend more money trying to search/develop a solution for this as compared to buying a third party component. Do not reinvent the wheel and go for the paid solution.

Printing is a complex problem and I would love to see the day when better framework support is added for this.

like image 64
Vaibhav Avatar answered Sep 30 '22 16:09

Vaibhav


Printing from a Windows service is really painful. It seems to work... sometimes... but finally it craches or throws an exception from time to time, without any clear reason. It's really hopeless. Officially, it's even not supported, without any explanation, nor any proposal for an alternate solution.

Recently, I have been confronted to the problem and after several unsuccessful trials and experimentations, I came finally with two viable solutions:

  • Write your own printing DLL using the Win32 API (in C/C++ for instance), then use it from your service with P/Invoke (works fine)
  • Write your own printing COM+ component, then uses it from your service. I have chosen this solution with success recently (but it was third party COM+ component, not own written) It works absolutely fine too.
like image 30
Yann Trevin Avatar answered Sep 30 '22 17:09

Yann Trevin