Gor
Gor

Reputation: 61

Save pdf report on database using BIRT

So, I'm trying to save the pdf report in database using service methode. I saw that there's a way to specify the output of the generated report by calling : pdfOptions.setOutputStream(output). But how can I call my save methode this way?

I saw this post but i'm stack at the persist point

I apreciate any advice

    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);

Upvotes: 0

Views: 247

Answers (1)

hvb
hvb

Reputation: 2668

You are streaming the output directly to the client with

pdfOptions.setOutputStream(response.getOutputStream());//opens report on browser

If you do this, your output gets consumed and you'll not be able to save it to the database.

I would use a "tee" like approach, you know, with one input stream and two output streams.

You could write that yourself, our you just use something like the Apache TeeOutputStream.

This could look like this:

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

Upvotes: 1

Related Questions