Question

I have started to use Flying Saucer for creating PDF from JSF files and it is great! Now I have a problem: I want to use it in our application for creating PDF without blocking HTTP response.

Please look the code below:

ServletOutputStream outputStream = response.getOutputStream();
ITextRenderer renderer = new ITextRenderer();
renderer.setDocument(new URL("http://localhost:8080/pdf2.faces").toString());
renderer.layout();
renderer.createPDF(outputStream);
outputStream.flush();

According to my understanding ITextRenderer loads the whole JSF in the line 3 (in the function loadDocument). It means ITextRenderer requires that the whole JSF will be created by a server.

Then, ITextRenderer creates PDF layout in the line 4 and put it in the outputStream in the line 5.

What if the creation of JSF will take a long time? The code above will stack in the line 3 till server creates the whole JSF. So, if I want to put the code from lines 1-6 in the servlet it can block HTTP response and can bring into the timeout issue. I want Flying Saucer will start to create the output stream HTTP response without waiting till the whole original JSF will be created. What is the best way to do it? Is Flying Saucer has any API support this? Any help will be appreciated.

Was it helpful?

Solution

I have found the following workaround using Flying Saucer API:

1) I redesigned my original JSF and load it in parts

2) I created the single PDF from the JSF parts as described in the Flying Saucer WIKI

http://code.google.com/p/flying-saucer/wiki/FAQPDF#How_can_I_print_multiple_pages_on_to_one_PDF,_if_they_come_from_multiple_documents

It works, but it is still workaround. If the loading of the JSF part will take a long time it can bring into the timeout issue. How to solve the problem? Any help will be appreciated.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top