如何以编程方式将Acumatica报告的PDF版本的多个页面保存到文件中?

时间:2018-12-13 18:23:36

标签: acumatica

我有一个报告,当手动运行时,该报告在PDF视图中每页成功打印出1条记录,并且也成功导出为PDF。

我需要以编程方式生成报告并将其保存到SO记录中。有了我的代码,我只会得到第一页。如何将所有页面保存到文件?

private IEnumerable ExportReport(PXAdapter adapter, string reportID, Dictionary<String, String> parameters)
    {
        //Press save if the SO is not completed 
        if (Base.Document.Current.Completed == false)
        {
            Base.Save.Press();
        }

        PX.SM.FileInfo file = null;
        using (Report report = PXReportTools.LoadReport(reportID, null))
        {
            if (report == null)
            {
                throw new Exception("Unable to access Acumatica report writer for specified report : " + reportID);
            }

            PXReportTools.InitReportParameters(report, parameters, PXSettingProvider.Instance.Default);
            ReportNode reportNode = ReportProcessor.ProcessReport(report);
            IRenderFilter renderFilter = ReportProcessor.GetRenderer(ReportProcessor.FilterPdf);

            //Generate the PDF
            using (StreamManager streamMgr = new StreamManager())
            {
                renderFilter.Render(reportNode, null, streamMgr);
                UploadFileMaintenance graphUploadFile = PXGraph.CreateInstance<UploadFileMaintenance>();
                file = new PX.SM.FileInfo(reportNode.ExportFileName + ".pdf", null, streamMgr.MainStream.GetBytes());
            }

            //Save the PDF to the SO; if it already exists save as a new version.
            UploadFileMaintenance graph = new UploadFileMaintenance();
            graph.SaveFile(file, FileExistsAction.CreateVersion);
            PXNoteAttribute.AttachFile(Base.Document.Cache, Base.Document.Current, file);
        }

        //Return the info on the file
        return adapter.Get();
    }

我也尝试过使用以下代码生成PDF:

//Generate the PDF
            byte[] data = PX.Reports.Mail.Message.GenerateReport(reportNode, ReportProcessor.FilterPdf).First();
            file = new PX.SM.FileInfo(reportNode.ExportFileName + ".pdf", null, data);  

并且似乎GenerateReport返回一个IList,所以我猜每个页面都是一个单独的列表项。将它们组合并另存为PX.SM.FileInfo的正确方法是什么?

1 个答案:

答案 0 :(得分:1)

正如HB_ACUMATICA在最后一条评论中所建议的那样,问题出在传递的参数上。我的代码中的参数名称错误,因此该参数进入报表空白。谢谢您指出正确的方向!