You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by Chris Faulkner <ch...@ntlworld.com> on 2002/04/19 14:58:58 UTC
JSP returning PDF
Hi
I'm using FOP in a JSP to return dynamically created PDF documents to browsers. I'm using the usual method of embedding FOP as described on the web site. It works great. The main problem is that the
PDFs take about 20 seconds to generate and then, since they are 500K or so, a while to download depending on connection speed.
I'd like to be able to put a message on an intermediate page which could refresh and only return the PDF when it is ready. At the moment, they are just seeing a blank page until the PDF is complete. Does
anyone have any ideas for this ? Can I flush some output to the page to advise them to be patient, then reset the response and send the PDF when it is ready?
Alternatively. I was thinking of doing something a bit more ambitious which would be to output the PDF to a database blob, then send back a page which refreshes to a JSP which keeps checking whether
the PDF has been finished. When it is, I could fetch the data outofthe BLOB and send it back.
I have seen other sites where the PDF was output to a static file on the website. Then the JSP would refresh and keep checking until the file was present. When the file was created, the page would
appear with a link to the file. The main problem with this is security. There is the potential that everyone would have access to all PDFs on the web site, although on a site without listings, they'd need to be
making pretty inspired guesses to find and download it.
How do others get around this ? I imagine its quite a common problem.
Thanks
Chris
Re: JSP returning PDF
Posted by Patrick Lanphier <pm...@artemisgroup.com>.
All one really has to do is example in PHP
function stall_browser($records,$file){
Header("Cache-Control: must-revalidate");
$minutes = floor(round(($records * .82)/60,2)); //Calulated at .77
$seconds = (round(($records * .82)/60,2)-$minutes) *60;
$offset = 60 * 60 * 24 * 0;
$ExpireString = gmdate("D, d M Y H:i:s", time() + $offset) . " GMT";
Header("Expires: " . $ExpireString);
echo "<META HTTP-EQUIV=Expires CONTENT=\"$ExpireString\">";
{put what you would like to see here on the page}
{flush}
{feed a small bitstream until completed}
for ($i=0;$i<2;$i++) echo str_repeat (' ',512) ."\n";
{when finished send}
echo "<div align='center'><a href='http://www.energywatchdog.com/usi/ind
echo "</body>\n";
echo "</html>\n";
echo "<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=http://www.energywatchdo
exit;
};
The refresh redirect is to the new PDF file. If you do this any other way
that I have tried it works in some browsers and not others this appears to
work in all broswers.
Patrick Lanphier
The Artemis Group
http://www.artemisgroup.com
phone: 814-235-0444
fax: 800-582-9710
On Fri, 19 Apr 2002, Chris Faulkner wrote:
> Hi
>
> I'm using FOP in a JSP to return dynamically created PDF documents to browsers. I'm using the usual method of embedding FOP as described on the web site. It works great. The main problem is that the
> PDFs take about 20 seconds to generate and then, since they are 500K or so, a while to download depending on connection speed.
>
> I'd like to be able to put a message on an intermediate page which could refresh and only return the PDF when it is ready. At the moment, they are just seeing a blank page until the PDF is complete. Does
> anyone have any ideas for this ? Can I flush some output to the page to advise them to be patient, then reset the response and send the PDF when it is ready?
>
> Alternatively. I was thinking of doing something a bit more ambitious which would be to output the PDF to a database blob, then send back a page which refreshes to a JSP which keeps checking whether
> the PDF has been finished. When it is, I could fetch the data outofthe BLOB and send it back.
>
> I have seen other sites where the PDF was output to a static file on the website. Then the JSP would refresh and keep checking until the file was present. When the file was created, the page would
> appear with a link to the file. The main problem with this is security. There is the potential that everyone would have access to all PDFs on the web site, although on a site without listings, they'd need to be
> making pretty inspired guesses to find and download it.
>
> How do others get around this ? I imagine its quite a common problem.
>
> Thanks
>
>
> Chris
>
>