I used 'process' to print pdf file in C# app.But i cannot get the print status.I found that it is possible to interact with printer/queue with System.management and System.printing.I did a lot of trial n error using these two namespaces but couldnt print a file.Any examples availble on how to use these to print a pdf doc to printer?
3 Answers
System.Printing cannot be used to print PDFs. PDFs has to be rendered to a printable file first.
See this question and its answers for a nice overview of different approaches.
If you're on linux you can easily call lp
command.

- 1
- 1

- 737
- 5
- 13
-
Some details on PDF rendering: https://www.debenu.com/blog/whats-difference-pdf-rendering-pdf-viewing-2.html – andrew.rockwell Aug 15 '19 at 20:09
This Question has already been answered here How can I send a file document to the printer and have it print?.
You cannot print a pdf with standard methods cause it needs to be rendered first, you can user Ghostscript, Adobe Acrobat or something else for that.
Edit: Johan was faster
-
1But these examples doesnt show how to get status of print ..They Use Process to print file.From those process is it possible get print status? I guess no!! – Murali Uppangala Nov 22 '13 at 11:42
-
@mmu not direct, no. But take a look at PrintServer.GetPrintQueues. This is can give you a printers status. Yo can check it in a second Thread or something. Im not sure if you look for the printers status or the print job status. If you want the print job status take a look at Win32_PrintJob. – BudBrot Nov 22 '13 at 11:53
If you have a WPF
application, then use System.Printing
.
Here's code:
var file = File.ReadAllBytes(pdfFilePath);
var printQueue = LocalPrintServer.GetDefaultPrintQueue();
using (var job = printQueue.AddJob())
using (var stream = job.JobStream)
{
stream.Write(file, 0, file.Length);
}
Now, this namespace must be used with a WPF
application. It does not play well with ASP.NET
or Windows Service
. It should not be used with Windows Forms
, as it has System.Drawing.Printing
. I don't have a single issue with my PDF printing using the above code, but I'm all ears as to why it doesn't work for someone else.
I should mention that you have to have a printer that will support direct printing, as you're sending the information directly to the printer. In my experience, this has worked with Brother HL series and Sharp enterprise printers. I wish this would work for other things, such as Excel documents, but it doesn't. Luckily, those are easy to print in other manners.

- 9,982
- 10
- 73
- 105
-
1It would be nice if whoever gave this a downvote would provide feedback that lead them to their decision. This has worked perfectly for me, but I'm all ears. There might have been a specific case and it would be nice if you shared with others. – B.K. Mar 09 '15 at 21:22
-
@KJ I did mention that you need to have a printer which supports direct printing... that's the last paragraph. – B.K. Aug 02 '23 at 18:45