Anonymous
07-09-2002, 05:21 PM
Hi, I think I can provide the servlet sample code, but I need some help:
Can someone provide me a JFreeReport HelloWorld?. The included demo is too big as to extract some simple code and test it on a servlet. I already know how to send a PDF from a servlet using IText (the PDF library used by JFreeReports).
I think that these are the basic steps to produce a report from a servlet:
1) get a report object given the XML file and the datasource
URL in = getClass ().getResource (urlname);
ReportGenerator gen = ReportGenerator.getInstance ();
JFreeReport report1 = null;
report1 = gen.parseReport (in, in);
report1.setData (data);
2) send the report to the PDF Target:
PrinterJob pj = PrinterJob.getPrinterJob ();
PageFormat pf = pj.validatePage (???reportPane.getPageFormat ()???);
ByteArrayOutputStream b = new ByteArrayOutputStream ();
PDFOutputTarget target = new PDFOutputTarget (b, pf, true);
target.open ("Title", "Author");
report1.processReport (target);
target.close ();
Q: How can I obtain the PageFormat without a reportPane?
3) send the pdf stream to the servlet
res.setContentType("application/pdf");
res.setContentLength(b.size());
ServletOutputStream out = res.getOutputStream();
out.write( b.toByteArray() );
out.flush();
out.close();
Any help will be very appreciated.
Best Regards,
Martin
Can someone provide me a JFreeReport HelloWorld?. The included demo is too big as to extract some simple code and test it on a servlet. I already know how to send a PDF from a servlet using IText (the PDF library used by JFreeReports).
I think that these are the basic steps to produce a report from a servlet:
1) get a report object given the XML file and the datasource
URL in = getClass ().getResource (urlname);
ReportGenerator gen = ReportGenerator.getInstance ();
JFreeReport report1 = null;
report1 = gen.parseReport (in, in);
report1.setData (data);
2) send the report to the PDF Target:
PrinterJob pj = PrinterJob.getPrinterJob ();
PageFormat pf = pj.validatePage (???reportPane.getPageFormat ()???);
ByteArrayOutputStream b = new ByteArrayOutputStream ();
PDFOutputTarget target = new PDFOutputTarget (b, pf, true);
target.open ("Title", "Author");
report1.processReport (target);
target.close ();
Q: How can I obtain the PageFormat without a reportPane?
3) send the pdf stream to the servlet
res.setContentType("application/pdf");
res.setContentLength(b.size());
ServletOutputStream out = res.getOutputStream();
out.write( b.toByteArray() );
out.flush();
out.close();
Any help will be very appreciated.
Best Regards,
Martin