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.