【问题标题】:Birt edition with two output streams具有两个输出流的 Birt 版本
【发布时间】:2015-02-24 16:01:18
【问题描述】:

我有一个从 Java EE 应用程序启动的 birt 版本,当用户启动操作时,pdf 生成会在新窗口中启动,一切正常,我想做的更改是:我想保持不变pdf 在我的服务器中以稍后通过电子邮件发送。

PDFRenderOption pdfOptions = new PDFRenderOption(options);
pdfOptions.setOutputFormat("pdf");
options.setSupportedImageFormats("JPG;BMP;PNG;JPEG");
pdfOptions.setOutputFileName(OUTPUT_LOCATION + "project/exportprojet.pdf");
pdfOptions.setOutputStream(response.getOutputStream());
runAndRenderTask.setRenderOption(pdfOptions);

添加pdfOptions.setOutputFileName(OUTPUT_LOCATION + "project/exportprojet.pdf");后,pdf生成并存储在服务器中,但之前的工作不再工作,向用户启动一个新窗口并且不显示pdf,看起来添加的行占用了生成的 pdf 并通过阻止它发送给用户将其放入服务器

【问题讨论】:

    标签: jakarta-ee pdf-generation birt outputstream


    【解决方案1】:

    不支持同时使用setOutputFileNamesetOutputStream

    但解决方案很明显: 只需将 PDF 生成到文件系统(使用setOutputFileName),等到您的RunAndRenderTask 完成,然后将文件的内容(二进制)复制到response.getOutputStream

    【讨论】:

    • 感谢您的回复,我刚刚添加了实现您的建议的代码行,感谢您验证我的修改以将您的答案标记为已接受:)
    【解决方案2】:

    hvb 提出的解决方案的实现完美运行,对我的旧代码进行了更改:

     PDFRenderOption pdfOptions = new PDFRenderOption(options);
    String sUrlExportFile = OUTPUT_LOCATION + "projet/" + idProjetAGenerer + "/exportprojet.pdf";
    pdfOptions.setOutputFormat("pdf");
    options.setSupportedImageFormats("JPG;BMP;PNG;JPEG");
    pdfOptions.setOutputFileName(sUrlExportFile);
    runAndRenderTask.setRenderOption(pdfOptions);
    runAndRenderTask.getAppContext().put(EngineConstants.APPCONTEXT_BIRT_VIEWER_HTTPSERVET_REQUEST, request);
    runAndRenderTask.run();
    runAndRenderTask.close();
    //copy the genereted file to response.getOutputStream()
    File f = new File(sUrlExportFile);
    InputStream inputStream = null;
    try {
        inputStream = new FileInputStream(f);
        IOUtils.copy(inputStream, response.getOutputStream());
    } finally {
        IOUtils.closeQuietly(inputStream);
    }
    

    【讨论】:

      猜你喜欢
      • 2018-07-02
      • 1970-01-01
      • 2019-02-27
      • 1970-01-01
      • 2014-07-12
      • 2016-10-10
      • 1970-01-01
      • 1970-01-01
      • 2012-09-13
      相关资源
      最近更新 更多