Play 2 Generate pdf file from Jasper file

361
April 03, 2017, at 4:46 PM

I have a jasper file in 'app/reports/reportname.jasper'. I want to generate a pdf from jasper file in my controller but i don't know how..

Here is my code..

JasperReportBase.java

public class BaseJasperReport {
static String REPORT_DEFINITION_PATH = "./app/reports/";
public static InputStream generateReport(String reportDefFile, Map    reportParams) {
OutputStream os = new ByteArrayOutputStream();
try {
  String compiledFile = REPORT_DEFINITION_PATH + reportDefFile + ".jasper";
  JasperCompileManager.compileReportToFile(REPORT_DEFINITION_PATH + reportDefFile + ".jrxml", compiledFile);
  JasperPrint jrprint = JasperFillManager.fillReport(compiledFile, reportParams, play.db.DB.getConnection());
  JRExporter exporter = new JExcelApiExporter();
  exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, os);
  exporter.setParameter(JRExporterParameter.JASPER_PRINT, jrprint);
  exporter.exportReport();
  JRExporter exporter1 = new JRPdfExporter();
  exporter1.setParameter(JRExporterParameter.JASPER_PRINT, jrprint);
  exporter1.setParameter(JRExporterParameter.OUTPUT_STREAM, os);
  exporter1.exportReport();
} catch (Exception e) {
  e.printStackTrace();
}
return new ByteArrayInputStream(((ByteArrayOutputStream) os).toByteArray());

} }

controller.java

public Result generateTransactionreceipt(String refNo) {
      ....?????
}

The pdf will generate when user click refNo

<a href="@transactions.controllers.routes.TransactionController.generateTransactionreceipt(model.getRefNo)">@model.getRefNo</a>

Hope someone can give me some help..

Rent Charter Buses Company
READ ALSO
How to parse JSON array without key using GSON

How to parse JSON array without key using GSON

I have a following JSON like this

587
how to create a event calendar in java [on hold]

how to create a event calendar in java [on hold]

I'm fresher to javaI want to create a calendar in java that has possibility to enter some events and view it on some day

489
Retrieving key value of an HashMap with ArrayList as a Object

Retrieving key value of an HashMap with ArrayList as a Object

I have created an HashMap with an ArrayList as Object

501
Check if timestamp older than 30 seconds

Check if timestamp older than 30 seconds

I am trying to determine if a timestamp is older than 30 seconds, but for some reason it is coming back as older than 30 seconds when it hasn't even been a couple seconds

591