[JAVA] Is possible use Jasper report in play framework?

962 views
Skip to first unread message

Leonan Luppi

unread,
Jun 13, 2014, 12:46:11 PM6/13/14
to play-fr...@googlegroups.com
Hello Everybody,

Someone has managed to use jasper reports in play application?

Thanks Folks!

Volker Hatz

unread,
Jun 13, 2014, 2:56:36 PM6/13/14
to play-fr...@googlegroups.com
You should be more specific on how you want to use it - do you mean the library only or the server?

We are using JasperReports Server and access the content via iframe and in the near future with their new visualize.js library which seems to be great for client side integration. There are no issues specific to Play in doing so. 

Volker

Leonan Luppi

unread,
Jun 13, 2014, 4:17:56 PM6/13/14
to play-fr...@googlegroups.com
Hello Volker,

So I want to make PDF File which jasper report.. Is possible? do you have an example?

Volker Hatz

unread,
Jun 13, 2014, 4:31:38 PM6/13/14
to play-fr...@googlegroups.com
This is not my use case. But this link should help in setting it up. The fact that itext has to be included lets me think that you can create PDF within the jasper reports library: this old tutorial should explain how you generate a pdf.

You should not expect however, that you can create a pdf rendering a play page. Tools like PhantomJS seem to be useful for that use case.

Leonan Luppi

unread,
Jun 13, 2014, 4:34:39 PM6/13/14
to play-fr...@googlegroups.com
PhantomJS? I never see this.. I'll search about.

Did you generate some PDF in Play! application if yes, how you do that?

andref...@gmail.com

unread,
Jun 15, 2014, 6:34:00 PM6/15/14
to play-fr...@googlegroups.com
Hi Leonan,

Yes, it`s possible to use Jasper Reports with Play framework ...for example:

public static Result generatePDFReport() {

String fileName="file";

final Map<String, String[]> values = request().body().asFormUrlEncoded();

try {

JasperCompileManager.compileReportToFile(fileName + ".jrxml");

Map<String, Object> parameters = new HashMap<String, Object>();

JasperCompileManager.compileReportToFile(fileName + ".jrxml");

JasperPrint print = JasperFillManager.fillReport(fileName

".jasper", null, play.db.DB.getConnection());

JRExporter exporter = new JRPdfExporter(); 

exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);

exporter.setParameter(JRExporterParameter.OUTPUT_STREAMnew FileOutputStream(fileName + ".pdf"));

exporter.exportReport();

return ok(new File(fileName + ".pdf"));

}

Put the jars files of Jasper Reports in lib folder.

Leonan Luppi

unread,
Jun 15, 2014, 6:41:22 PM6/15/14
to play-fr...@googlegroups.com
Oh very nice.. I'll test that..

This display in the browser or only gerenate a file?

Thanks!!
Reply all
Reply to author
Forward
0 new messages