Handling 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.
public delegate void PrintJobEventHandler(Object sender, PrintJobEventArgs e)
Implement event handling by defining an event handler and then assigning the handler to the PrintJob instance. The following example demonstrates.
NOTE: Firing these events is limited to the capabilities of a particular printer. Not all printers report job statuses the same, and some printers do not report these statuses. Some printers might not accurately report print job status to the 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);
}
}
}
GitHub
Refer to the print-manager-dotnet-core project on GitHub for examples demonstrating how to use the DynamicPDF PrintManager for .NET. Examples are provided by the following two files.
- EventsExample.cs
- EventsExample.vb