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.
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.
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.
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.
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 ();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With