Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect when a PrintDocument successfully prints (not just previewed)

I'm doing some custom printing using a PrintDocument in my application. I have a requirement of logging when our items are successfully printed. I originally achieved this with something like:

 print_doc.EndPrint += (o,e) => printed_callback ();

To make my printed_callback get invoked when a print finished. However, now that I'm adding preview support, I'm passing a PrintDocument constructed in exactly the same way into a PrintPreviewDialog. Doing so causes the EndPrint event to be invoked after the initial rendering of the printout needed for the preview.

As a result, even if a user clicks "Preview" and then just closes the preview, our logging code gets invoked.

Any suggestions for how to differentiate between a real printout and a "preview print" ? Unfortunately, I can't just not hook up to EndPrint for the PrintDocument passed to the PrintPreviewDialog since the user may click the "Print" button in the preview dialog and trigger a printout.

like image 335
Pete Avatar asked Jun 07 '11 19:06

Pete


People also ask

Does a printer keep history of what is printed?

Before letting go of any electronic gadget, you need to make sure it doesn't contain any personal information. With a standalone printer, it doesn't retain anything, but an all-in-one might have saved documents, scans, print logs or fax logs.

Why is my printer not printing what is previewed?

The solution is to make sure the Update Fields check box is cleared, and then manually update all fields before using Print Preview and subsequently printing. Another check box on the Print tab of the Options dialog box can also cause differences in formatting on a printout.

How can I find out who printed my network printer?

Once your printer history is enabled, you can access it at any time from the Event Viewer. To do so, find and open the “PrintService” category and then click on the “Operational” log. A history of all Windows printer events will be listed, from initial printer spooling to completed or failed prints.


1 Answers

Ok, so I actually managed to figure this out myself, using the PrintDocument.PrintController property, and checking the IsPreview property of the controller. My final coded ended up as follows:

doc.EndPrint += (o,e) =>
{
    if (doc.PrintController.IsPreview)
        return;

    print_callback ();
}
like image 62
Pete Avatar answered Nov 15 '22 19:11

Pete