Posts

Showing posts from January, 2025

C# Print PDF programatically

 Implement this answer https://stackoverflow.com/questions/47857500/c-sharp-how-to-programmatically-print-an-existing-pdf-file-using-printdocument#answer-48537329 1. Make sure you install (via NuGet)  PdfiumViewer   but only version 2.10.0 other versions does quite a mess... then run this code and thats it              var path = @"C:\temp\test2.pdf"; using (var document = PdfDocument.Load(path)) {   using (var printDocument = document.CreatePrintDocument()) {     printDocument.PrinterSettings.PrintFileName = "test2.pdf";     printDocument.PrinterSettings.PrinterName = printersNames[pi];     printDocument.DocumentName = "test2.pdf";     printDocument.PrinterSettings.PrintFileName = "test2.pdf";     printDocument.PrintController = new StandardPrintController();     printDocument.Print();   } } Now please ask me how to get your printer name       ...