outputting a generated PDF file
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Monday, August 26, 2002 11:30 AM

Hi

I'm generating a pdf file based on some Data out of a database.
basically user clicks on the create report link on a page, the page uses some parameters(date and report type) to create a pdf report and then its supposed to spit the report at the user. How to i get it to send the report down the line without creating the report and saving it to the server? Am I being dumb?

Evan Brown

Re: outputting a generated PDF file

Posted By:   Lasse_Koskela  
Posted On:   Monday, August 26, 2002 12:28 PM

Write a servlet, which does something like this:

public void service(request, response) throws ...
{
response.setContentType(MIME_TYPE_PDF);
InputStream pdf = ...;
OutputStream out = response.getOutputStream();
while (...)
{
// read from pdf
// write to out
}
}


You can get the pdf stream from another servlet, a regular Java class, file, etc. You can also set some header, which implies the pdf document's suggested filename for the browser (although all browsers don't use that information).


This subject has been around for a while and the net is full of answers on different forums.

About | Sitemap | Contact