如何以编程方式将Acumatica报告的PDF版本的多页保存到文件中?
我有一个报告,当手动运行时,在PDF视图中成功地打印出每页1条记录,并且将其导出为PDF也是成功的 我需要以编程方式生成报告并将其保存到SO记录。用我的代码,我只得到了第一页。如何将所有页面保存到文件中如何以编程方式将Acumatica报告的PDF版本的多页保存到文件中?,acumatica,Acumatica,我有一个报告,当手动运行时,在PDF视图中成功地打印出每页1条记录,并且将其导出为PDF也是成功的 我需要以编程方式生成报告并将其保存到SO记录。用我的代码,我只得到了第一页。如何将所有页面保存到文件中 private IEnumerable ExportReport(PXAdapter adapter, string reportID, Dictionary<String, String> parameters) { //Press save if the
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();
}
GenerateReport似乎正在返回一个IList,所以我猜每个页面都是一个单独的列表项。组合它们并另存为PX.SM.FileInfo的正确方法是什么?正如HB_ACUMATICA在上一篇评论中所建议的,问题在于传递的参数。我的代码中有一个参数命名错误,所以报告中没有该参数。谢谢你指出了正确的方向 我认为IList适用于多个组合报告,否则将PDF作为电子邮件附件发送会有类似的1页问题,但我没有测试它。我测试了手动生成的报告中的Send,该文件包含所有页面。你对我在代码中的错误有什么建议吗?我只得到了一个页面?没有线索,我发布了一个答案,但删除了它,因为它没有带来任何特别有用的东西。您可以通过调用ToList而不是First并检查是否有多于1个元素来验证生成报告返回每页的假设。此外,通过在报表中显示参数,可以检查从UI调用报表参数时是否与以编程方式调用报表参数时相同。
//Generate the PDF
byte[] data = PX.Reports.Mail.Message.GenerateReport(reportNode, ReportProcessor.FilterPdf).First();
file = new PX.SM.FileInfo(reportNode.ExportFileName + ".pdf", null, data);