使用 BIRT 在数据库中保存 pdf 报告

Save pdf report on database using BIRT

所以,我正在尝试使用服务方法将 pdf 报告保存在数据库中。我看到有一种方法可以通过调用来指定生成的报告的输出:pdfOptions.setOutputStream(output)。但是我怎样才能这样调用我的保存方法呢?

我看到了这个 post 但我在坚持点

我很感激任何建议

    PDFRenderOption pdfOptions = new PDFRenderOption(options);
    pdfOptions.setOutputFormat(FORMAT_PDF);
    pdfOptions.setOption(IPDFRenderOption.PAGE_OVERFLOW, IPDFRenderOption.OUTPUT_TO_MULTIPLE_PAGES);
    pdfOptions.setOutputStream(response.getOutputStream());//opens report on browser
    runAndRenderTask.setRenderOption(pdfOptions);

您正在使用

将输出直接流式传输到客户端
pdfOptions.setOutputStream(response.getOutputStream());//opens report on browser

如果您这样做,您的输出将被消耗,您将无法将其保存到数据库中。

我会使用一种类似于 "tee" 的方法,你知道,一个输入流和两个输出流。

你可以自己写,我们你只需要使用类似 Apache TeeOutputStream 的东西。

这可能是这样的:

OutputStream blobOutputStream = ...; // for writing to the DB as BLOB.
OutputStream teeStream = TeeOutputStream(response.getOutputStream(), blobOutputStream);
pdfOptions.setOutputStream(teeStream);