3

I want to build a Windows Service in C# which listens to an MSMQ queue for incoming print command messages. A message references a PDF document und contains the name of the destination printer (and maybe some other metadata like numbers of copies to print). The service should pick up the PDF and print it on the destination printer.

Question: Is it possible to print an arbitrary PDF on a printer from a Windows Service?

supplement:

The implementation should not depend on Acrobat Reader or any other "GUI tool". The Windows service runs headless. Besides I want to avoid to start a separate process for each print job when this is possible.

Olaf
  • 3,786
  • 4
  • 25
  • 38
  • 1
    see this http://stackoverflow.com/questions/5596394/how-to-print-pdf-document-from-windows-service – Ahror Kayumov Aug 11 '15 at 11:16
  • The solution should not depend on Acrobat Reader. – Olaf Aug 11 '15 at 11:20
  • .NET has no native PDF support so you will need a library or executable to do the printing. – CodeCaster Aug 11 '15 at 11:27
  • Yes, I'm aware of this. I have already tried multiple libraries but untill now I could not find one which really works. – Olaf Aug 11 '15 at 11:35
  • Please can somebody explain the down vote? – Olaf Aug 11 '15 at 12:13
  • @Olaf: downvotes are often inexplicable, I'm afraid. Some people will downvote anything. – Harry Johnston Aug 12 '15 at 02:45
  • Quite an old post but I was wondering if you found a solid solution to your problem? I've recently been given a feature to implement printing from a windows service. Basically look up file, pass to printer. Don't really need opening/loading docs, just straight to printer. – Tez Wingfield Aug 11 '17 at 10:11
  • Yes, that was long ago. I think we had some success with Spire.PDF. At least I've learnt that you have to go with a commercial product. There are no good opensource libraries available for this task. – Olaf Aug 11 '17 at 13:46

1 Answers1

3

I use Spire.PDF library. The free version has a limit of 10 pages per file. No UI or Acrobat dependence

https://www.nuget.org/packages/Spire.PDF/

   PdfDocument pdfdocument = new PdfDocument();
   pdfdocument.LoadFromFile(path);
   pdfdocument.PrinterName = printername;
   pdfdocument.PrintDocument.PrinterSettings.Copies = copiesNumber;
   pdfdocument.PrintDocument.Print();
   pdfdocument.Dispose();
Murilo
  • 1,112
  • 1
  • 18
  • 33
  • I'm already tried Spire.PDF. Unfortunately I ran into concurrency problems. But I got the problems only in the context of Windows Service applications. No exceptions in simple console apps or ASP.NET apps. – Olaf Aug 11 '15 at 11:43
  • Should this app be a windows service? Can it be a WPF application, so that you can hide it on systray. The software I'm working with has some monitors that act on background, but they are WPF and use systray. works very well. I hope you can do that. – Murilo Aug 11 '15 at 11:47
  • I think conceptionally the application should be a window service. It is an headless service running on a backend machine. A WPF app is not a good fit because WPF apps "are for desktops". Initially I thought this should be easy but now I'm not sure that it is possible. – Olaf Aug 11 '15 at 11:57
  • Print from windows service http://www.c-sharpcorner.com/UploadFile/87ad51/printing-from-a-windows-service/ – Sakthivel Aug 12 '15 at 12:00
  • E-iceblue have fixed the concurrency problems in Spire.PDF in version 3.5. – Olaf Aug 19 '15 at 06:41