View Full Version : Webbased report

07-18-2002, 10:46 PM
I am developing a website, and i want to generate reports on web as pdf so that the user can download on his machine, i dont want to install any thing on client machine.
is it possible to do this with jfreereport,
ahs any one tried it,
or does anyone know of such a tool


07-19-2002, 02:27 PM
There's nothing to stop you using JFreeReport to generate PDF content using servlets or JSP...but there isn't any demo code for this yet. Contributions are welcome...



07-19-2002, 04:10 PM
I haven't tried it on servlet or jsp, but I have tried it on Java Applet.
I have successfully tested on it. However, since the jfreereport invloves some access of system resource, it has violated the security issue of Applet. I solve it by tracing and modifying the source codes.

07-26-2002, 12:28 PM
I believe I have succesfully modified the demo to work from a servlet. It is definitely not the most elegant approach but it is working for me.

First, I created a copy of the JFreeReportDemo class and commented out all of the setvisible calls. I then added a function that duplicated the main function but forced a preview call and a print call.

I then copied the attemptSaveAs function in PreviewFrame and created a function that created the PDF based in on a File object passed in rather than one selected through the FileSelect.

Future work (havent gotten that far yet) appears to be removing all of the unnecessary SWING objects and changing the SampleData classes so they are database driven.

Once again, I dont claim this to be the most elegant solution there is probably a way of doing it without using the swing objects and there is some work in making the SampleData class more elegant that Im glossing over but you get what you paid for right? ;-)

07-26-2002, 12:30 PM
One more not, I would run this directly from the servlet, I will probably create a bean that calls the function (passing in the appropriate report type and file name)

07-26-2002, 03:53 PM
Hi Dan,

Thanks for your post...it sounds like you have a "proof of concept" to show that JFreeReport can work with servlets. I'd jump in and help you, but I don't know much about servlets (need to learn sometime though).



08-05-2002, 04:15 AM
Hi Dan,
I tried to modify JFreeReportDemo and PreviewFrame to create a PDF file and to call attemptSaveAs function in PreviewFrame to save the PDF file in disk. When I run JFreeReportDemo as Java application, it works well. But when I tried to do the same thing in JSP. It told me that there was a javax.servlet.ServletException: com/lowagie/text/DocumentException. I tried to debug it, I found the code line PDFOutputTarget target = new PDFOutputTarget (out, pf, true) in PreviewFrame didn't work. Would you tell me why? and How did you do that?

Best Regards,

Yuebin Li

08-12-2002, 09:50 PM
im using jfreereport from a servlet to generate pdf. ok heres a working sample code (this will download the generated pdf from the browser):

public void generatePDF(OutputStream out) throws Exception {
report = gen.parseReport("c:\sampleReport.xml");
report.setData(new ReportSet());
PDFOutputTarget target = new PDFOutputTarget(out, new PageFormat(), true);
target.open("Title", "Author");


ReportSet (my class) is a subclass of AbstractTableModel. see SampleData1.java to SampleData6.java from the demo package.


and calling the method generatePDF would look like :

response.setHeader("Content-Disposition", "attachment; filename=\"" + "unknown.pdf" + "\"");
ServletOutputStream out = response.getOutputStream();