PDFtoPrinter .NET is a library for .NET that allows us to print a PDF very easily from an application written in C#.
To do this, it uses PDFtoPrinter, a command-line tool that allows printing PDF files to a default printer. Internally, it uses a free version of Tracker Software Products :: PDF-XChange Editor.
Using PDFtoPrinter from C# is not too complicated. But we can make it even simpler thanks to the .NET wrapper.
PDFtoPrinter .NET adds the console application as a resource to the application, so we don’t have to download and include it as a resource. We simply add the Nuget package and we are ready to go.
It is a very simple library, lacking options to customize printing, such as choosing paper format or orientation.
However, if you simply need to print a PDF from a C# application, it is possibly the easiest and fastest way to add this functionality to your project.
How to use PDFtoPrinter
We can easily add the library to a .NET project through the corresponding Nuget package.
Install-Package PDFtoPrinter
Next, printing a file is as simple as doing.
var filePath = "c:\path\to\pdf\file.pdf";
var networkPrinterName = "\\myprintserver\printer1";
var printTimeout = new TimeSpan(0, 30, 0);
var printer = new PDFtoPrinterPrinter();
printer.Print(new PrintingOptions(networkPrinterName, filePath), printTimeout);
PDFtoPrinter is Open Source, and all the code and documentation is available in the project repository at https://github.com/svishnevsky/PDFtoPrinter

