Page 1 of 1

Determining when a report has been printed

PostPosted: Thu Dec 18, 2025 1:12 pm
by DannyC
Not sure if this should go in the Crystal Reports forum?

I've got a report ran from the menu.
When it's displaying on the screen in Print Preview, I need to write a plugin to intercept when it gets physically printed.

It's a report that shows open sales orders ready for picking in a format specific to this client. It's basically just consolidating the pickable lines by PartNo summing the Qty required.

When they print the report they also want Delivery Dockets printed for the orders using the InvoiceHistoryIDs which aren't displayed in the report but are available in the report source data.

I'm stumped on knowing how to start and what event(s) to hook into, getting the InvoiceHistoryID out of the report source, then printing the delivery dockets direct to the same printer that this report is going to.

Re: Determining when a report has been printed

PostPosted: Thu Dec 18, 2025 2:39 pm
by DannyC
Just further to this, I've found the business logic JiwaFinancials.Jiwa.JiwaApplication.JiwaPrintReport.JiwaPrintReport.
I'm going to try hooking into the event AfterPrintOutputControllerPrintReport.

From there I should be able to determine the report properties to ensure I am only dealing with the report I need, not just any random report.

I'll see how far I progress and maybe post a half-arsed plugin here for some feedback.

EDIT:
So this is what I have so far. When I print, nothing happens. Well, I get my harcopy output but the event isn't firing my code.
Code: Select all
#region "BusinessLogicPlugin"
public class BusinessLogicPlugin : System.MarshalByRefObject, JiwaFinancials.Jiwa.JiwaApplication.IJiwaBusinessLogicPlugin
{

    public override object InitializeLifetimeService()
    {
        // returning null here will prevent the lease manager
        // from deleting the Object.
        return null;
    }

    public void Setup(JiwaFinancials.Jiwa.JiwaApplication.IJiwaBusinessLogic JiwaBusinessLogic, JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin)
    {
      if (JiwaBusinessLogic is JiwaFinancials.Jiwa.JiwaApplication.JiwaPrintReport.JiwaPrintReport)
      {
         JiwaFinancials.Jiwa.JiwaApplication.JiwaPrintReport.JiwaPrintReport reportPrint = (JiwaFinancials.Jiwa.JiwaApplication.JiwaPrintReport.JiwaPrintReport)JiwaBusinessLogic;
         reportPrint.AfterPrintOutputControllerPrintReport += InterceptReportPrinting;
         
      }
    }
   
   private void InterceptReportPrinting(ref JiwaFinancials.Jiwa.JiwaApplication.JiwaPrintReport.JiwaPrintReport jiwaPrintReport, ref JiwaFinancials.Jiwa.JiwaApplication.PrintGroup.Maintenance.LogicalPrinter printer, ref int copies, ref CrystalDecisions.ReportAppServer.Controllers.PrintReportOptions PrintReportOptions)
   {
      System.Diagnostics.Debugger.Launch();
      MessageBox.Show(jiwaPrintReport.Report.FileName);
   }
}
#endregion

Re: Determining when a report has been printed

PostPosted: Thu Dec 18, 2025 4:57 pm
by Mike.Sheen
DannyC wrote: the event isn't firing my code.


How is the actual print triggered?

Is it from the Crystal Reports report viewer toolbar?
CrystalReportsToolbar.png
CrystalReportsToolbar.png (26.19 KiB) Viewed 9098 times


Because that won't raise the AfterPrintOutputControllerPrintReport event -that's part of the Crystal Reports Viewer control and that's it's own thing.

If that is how you are triggering the print, then you would need to jump through some hoops like we do for exporting using the export tool - we basically hide the toolbar button and add our own, and tell the toolbar to invoke our own method instead of the standard one.

High degree of difficulty.

If it is not from the Crystal Reports Viewer control toolbar, then where?

Re: Determining when a report has been printed

PostPosted: Thu Dec 18, 2025 5:37 pm
by DannyC
Is it from the Crystal Reports report viewer toolbar?


yes