PrintDocument: Hooking into the "Print" event

  • Thread starter Thread starter Bryan Valencia
  • Start date Start date
B

Bryan Valencia

Guest
I have this code...

using (PrintDocument printDoc = new PrintDocument())
{
printDoc.PrinterSettings.PrinterName = printDialog1.PrinterSettings.PrinterName;
printDoc.DocumentName = "Label";
printDoc.PrinterSettings = printDialog1.PrinterSettings;

PaperSize size = getPaperSize();
printDoc.DefaultPageSettings.PaperSize = new PaperSize("Label", size.Width, size.Height);

PrintPreviewDialog ppd = new PrintPreviewDialog();

printDoc.PrintPage += printPage;
printDoc.EndPrint += DonePrinting;
ppd.Document = printDoc;
ppd.ShowDialog();
}


This works amazingly, but I have a problem.

I need to log the print event to a database.

If I add the logging to the DonePrinting event (as shown), it logs when the preview is generated, AND when the job is sent to the printer (print button on the preview screen).

If I add it to this routine, it logs when the preview dialog is opened, whether or not it gets printed.


What I need is to hook into the actual printing of the label and log it ONLY if printed on the printer.

I tried to see if the EndPrint event had any indication if it was sending to a printer or a bitmap, but alas.




I'd rather live with false hope than with false despair.

Continue reading...
 
Back
Top