Handling PrintManager Events
PrintManager exposes a Starting, Failed, Succeeded, and Updated event on the PrintJob that requests the status of the particular PrintJob within the print spooler.
PrintJobEventHandler Delegate
The PrintJobEventHandler is a method called when a job is starting, succeeds, or fails. Implement event handling by defining an event handler and then assigning the handler to the PrintJob instance. The following example demonstrates.
The firing of these events depends on the capabilities of the specific printer and printer driver being used. Not all printers report print job statuses in the same way, and some printers may not report certain statuses at all. Additionally, some printers and drivers do not accurately communicate print job status information to the Windows print spooler.
using System;
using ceTe.DynamicPDF.Printing;
namespace PrintManagerConsole
{
class Program
{
static void Main(string [] args)
{
PrintJob printJob = new PrintJob(Printer.Default, pdfFilePath);
printJob.Failed += new PrintJobFailedEventHandler(printer_PrintJobFailed);
printJob.Succeeded += new PrintJobEventHandler(printer_PrintJobSucceeded);
printJob.Updated += new PrintJobEventHandler(printer_PrintJobUpdated);
printJob.Print();
}
static void printer_PrintJobFailed(object obj, PrintJobFailedEventArgs e)
{
Console.WriteLine("Print Failed : JobID = " + e.PrintJob.JobId + " Exception.Message = " + e.Exception.Message);
}
static void printer_PrintJobSucceeded(object obj, PrintJobEventArgs e)
{
Console.WriteLine("Print Succeeded : JobID = " + e.PrintJob.JobId);
}
static void printer_PrintJobUpdated(object obj, PrintJobEventArgs e)
{
Console.WriteLine("PrintJob Updated : JobID = " + e.PrintJob.JobId + ", Status = " + e.PrintJob.Status + ", Pages Printed = " + e.PrintJob.PagesPrinted);
}
}
}
Imports System
Imports ceTe.DynamicPDF.Printing
Namespace PrintManagerConsole
Module Module1
Sub Main()
Dim MyPrintJob As PrintJob = New PrintJob(Printer.Default, pdfFilePath)
AddHandler MyPrintJob.Failed, AddressOf Printer_PrintJobFailed
AddHandler MyPrintJob.Succeeded, AddressOf Printer_PrintJobSucceeded
AddHandler MyPrintJob.Updated, AddressOf Printer_PrintJobUpdated
MyPrintJob.Print()
End Sub
Sub Printer_PrintJobFailed(ByVal sender As Object, ByVal e As PrintJobFailedEventArgs)
Console.WriteLine("Print Failed : JobID = " & e.PrintJob.JobId & " Exception.Message = " & e.Exception.Message)
End Sub
Sub Printer_PrintJobSucceeded(ByVal sender As Object, ByVal e As PrintJobEventArgs)
Console.WriteLine("Print Succeeded : JobID = " & e.PrintJob.JobId)
End Sub
Sub Printer_PrintJobUpdated(ByVal sender As Object, ByVal e As PrintJobEventArgs)
Console.WriteLine("PrintJob Updated : JobID = " & e.PrintJob.JobId & ", Status = " & e.PrintJob.Status & ", Pages Printed = " & e.PrintJob.PagesPrinted)
End Sub
End Module
End Namespace
[EventsExample.cs](https://github.com/DynamicPDF/print-manager-dotnet-core/blob/master/print-manager-dotnet-core-cs/EventsExample.cs){#gitlink-id target=_blank}
[EventsExample.vb](https://github.com/DynamicPDF/print-manager-dotnet-core/blob/master/print-manager-dotnet-core-vb/EventsExample.vb){#gitlink-id target=_blank}