0

我正在尝试通过在后台使用 JasperReports 的 DynamicReports 生成 PDF 文件。我尝试在本地机器上生成 50 个 pdf 文件。它运行良好,生成文件并将其上传到我的 aws S3 客户端大约需要 35 秒。

将 JAR 上传到服务器后,服务器需要 50 秒来生成每个 PDF 文件。因此,在 s3 中生成和上传 50 个文件总共需要 2500 秒。每个文件大约 3 或 4 kb

更新:我尝试在服务器中进行更多调试。据我发现, toPdf 函数需要很多时间。不确定这是因为 toPdf 或将文件流存储在服务器中

代码片段:

            try {
              String directory = "/home/ubuntu/generatedFiles";
              for(Invoice eachInvoice : invoiceList){
                  JasperReportBuilder report = design.build(eachInvoice);
                  String fileName = "invoice_"+eachInvoice.getId()+".pdf";
                  String filePath= directory+"/"+fileName;
                  FileOutputStream stream = new FileOutputStream(filePath);
                  report.toPdf(stream);
                  client.uploadDocument(filePath, fileName);
              }
              // Delete all the files in the generatedFiles folder
              File file = new File(directory);      
              String[] invoiceFiles;    
                  if(file.isDirectory()){
                    // Delete the files from machine
                  }
              } 
           catch (DRException e) {
                     e.printStackTrace();
           }

如果有人可以帮助我解决这个问题!这一定非常棒!!

4

0 回答 0