I'm trying to programmatically print pdfs using c#. I tried different libraries (PostSharp, PDFium, etc.) as well as the adobe SDK. However, I have not been able to find anything about printing and stapling the printouts.
I tried using the PrintTicket object (Microsoft) to set the Stapling property but it's not working. I have verified that I have the right print drivers installed. I am able to staple printouts when I print manually so I'm sure the printer supports it.
I edited the post to include the full code. The PDF library I'm using here is PdfiumViewer. I'm not checking the return value in this code but if I run this, the return value I get gives me "ConflictStatus.ConflictResolved".
using (var server = new PrintServer("print server name"))
{
var printerName = "printer with stapling capabilities name";
var queues = server.GetPrintQueues();
using (var queue = queues.FirstOrDefault(x => x.FullName == printerName))
{
var printTicket = queue.DefaultPrintTicket;
printTicket.Collation = Collation.Collated;
printTicket.Stapling = Stapling.StapleTopLeft;
queue.UserPrintTicket = printTicket;
queue.CurrentJobSettings.CurrentPrintTicket = printTicket;
var ret = queue.MergeAndValidatePrintTicket(queue.UserPrintTicket, printTicket);
using (var pdfDoc = PdfDocument.Load("path to pdf"))
{
using (var printDoc = pdfDoc.CreatePrintDocument())
{
printDoc.PrinterSettings.PrinterName = printerName;
printDoc.PrinterSettings.ToPage = 2;
printDoc.Print();
}
}
}
}