簡體   English   中英

如何以編程方式將Acumatica報告的PDF版本的多個頁面保存到文件中?

[英]How can I save multiple pages of the PDF version of an Acumatica report to a file programmatically?

我有一個報告,當手動運行時,該報告在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的正確方法是什么?

正如HB_ACUMATICA在最后一條評論中所建議的那樣,問題出在傳遞的參數上。 我的代碼中的參數名稱錯誤,因此該參數進入報表空白。 謝謝您指出正確的方向!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM