Actually a very quick way is to simply copy the file to the path to the printer.
This works for both word docs and pdf. However, this involves a couple of things:
1.) Documents are stored where you could copy them.
2.) You have the printer driver installed on your web server.
3.) Adobe Reader must be installed on the web server. (otherwise printers sometimes do not recognize PDF).
So what I am doing is requesting printers on the server using ManagementObjectSearcher to find the default printer or any other that you want to capture for the path to the printer, and then copy the file to the path. That's all. The code is really simple.
public static class PrinterHelper { public class PrinterSettings { public string Name { get; set; } public string ServerName { get; set; } public string DeviceId { get; set; } public string ShareName { get; set; } public string Comment { get; set; } public bool Default { get; set; } }
This is how to use an assistant. i.e.
var printer = PrinterHelper.GetAllPrinters().FirstOrDefault(p => p.Default); PrinterHelper.SendFileToPrinter(printer.Name, "C:\\Users\\Public\\Documents\\Form - Career Advancement Request.pdf");
source share