I know the tag says Windows Forms
... but, if anyone is interested in a WPF
application method, System.Printing
works like a charm.
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);
}
Just remember to include System.Printing
reference, if it's not already included.
Now, this method 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.
I should mention, however, that if your printer does not support Direct Print for PDF file format, you're out of luck with this method.