Print SSRS report from C# code outside of Epicor

Just to quickly test out the rest of the code, I used LPR. Need to discuss with my manager if we want to stick with that or use Adobe or an open source option.

                            Byte[] returnRpt = adpRptMon.GetReportBytes(adpRptMon.ReportMonitorData.SysRptLst[0].SysRowID);
                            if (returnRpt.Length > 0)
                            {
                                System.IO.File.WriteAllBytes(@"C:\Temp\report.pdf", returnRpt);
                                //Print Here
                                var command = @"%WINDIR%\Sysnative\lpr -S 10.31.45.4 -P ""DD250"" ""C:\Temp\report.pdf""";
                                ProcessStartInfo procStartInfo = new ProcessStartInfo("cmd", "/C " + command);
                                procStartInfo.RedirectStandardOutput = true;
                                procStartInfo.UseShellExecute = false;
                                procStartInfo.RedirectStandardError = true;
                                procStartInfo.CreateNoWindow = true;
                                Process proc = new Process();
                                proc.StartInfo = procStartInfo;
                                proc.Start();
                                proc.WaitForExit();
                                string cmdError = proc.StandardError.ReadToEnd();
                                string cmdOutput = proc.StandardOutput.ReadToEnd();
                                Misc.TraceLog.Write(string.Format("Report size: [{0}].", returnRpt.Length.ToString()));
                                Misc.TraceLog.Write(string.Format("cmdError: [{0}].", cmdError));
                                Misc.TraceLog.Write(string.Format("cmdOutput: [{0}].", cmdOutput));
                            }

Later when you upgrade, if you want to actually have Epicor print it, we could modify it to send it to the Edge Agent (Server Side), and have it take care of it.

I’m not familiar with that. I’ll have to do some research.

Hey @Evan_Purdy . Just want you to know how helpful your code is as I’m starting to convert this WinForms app to REST. My REST calls are slightly different since I need async but I definitely would’ve struggled more if I didn’t have your example to follow. I’m a bit of a lone ranger Epicor developer at my company so this forum has been invaluable to me. It’s pretty awesome that I got two solutions out of one question!
Thanks again for sharing your knowledge!
Kelly

2 Likes

main-qimg-9e040c60fdb3375f8cfaa77823a93589