0

I am currently trying to add a combined report to an email attachment via a notification activity. I have currently achieved such functionality with a standard report that is not combined using help from stack overflow question: How do we attach report PDF/Excel file when i click on custom action on Sales order screen using Acumatica code .

However, it appears that I need to convert the combined report into a byte array in order to use sender.AddAttatchment(). I have tried generating both reports like this, and concatenating them together to make one byte array, but it will only display the last report that was loaded:

            //Load First Report
            PX.Reports.Controls.Report _report = PXReportTools.LoadReport("AR010000", null);
            PXReportTools.InitReportParameters(_report, parameters,
                    SettingsProvider.Instance.Default);
            PX.Reports.Data.ReportNode reportNode = PX.Reports.Data.ReportProcessor.ProcessReport(_report);

            //Create Byte Array From First report
            byte[] first = PX.Reports.Mail.Message.GenerateReport(reportNode,
                 ReportProcessor.FilterPdf).First();

            //Load Second Report
            PX.Reports.Controls.Report _report2 = PXReportTools.LoadReport("AR010000", null);
            PXReportTools.InitReportParameters(_report2, parameters,
                    SettingsProvider.Instance.Default);
            PX.Reports.Data.ReportNode reportNode2 = PX.Reports.Data.ReportProcessor.ProcessReport(_report2);

            //Create Byte Array From Second Report
            byte[] second = PX.Reports.Mail.Message.GenerateReport(reportNode2,
                 ReportProcessor.FilterPdf).First();

            //Concat Both Byte Arrays

            byte[] finalReport = new byte[first.Length + second.Length];
            Buffer.BlockCopy(first, 0, finalReport, 0, first.Length);
            Buffer.BlockCopy(second, 0, finalReport, first.Length, second.Length);

            //Attatch The Reports To The Email
            sender.AddAttachment("Combined Report.pdf", finalReport.ToArray());

Normally, to create a combined report, I would use this piece of code:

 //Generate Combined Report 
            PXReportRequiredException combineReport = PXReportRequiredException.CombineReport(null, "AP010000", new Dictionary<string, string>(), false);

            //Convert Combined Report To Byte Array
            byte[] report = PX.Reports.Mail.Message.GenerateReport(combineReport,
                 ReportProcessor.FilterPdf).First();

However, I am not sure how I can convert this to a byte array as it does not work with this code, as I get the error

Unable to cast object of type 'PX.Data.PXReportRequiredException' to type 'PX.Reports.Data.ReportNode'.

Does anybody have any ideas how I can go about this, or if there is some assembly reference I can use similar to the one that is used to convert the none combined report to a byte array, that uses PXReportRequiredException?

Thanks everybody

kieron
  • 332
  • 3
  • 19

1 Answers1

0

Unfortunately concatenating byte arrays will not achieve what you want. You need to find a 3rd party library, when I needed to do this I used PDFSharp. Take a look here

Combining multiple PDFs using PDFSharp

Kyle Vanderstoep
  • 688
  • 4
  • 10