- commons-beanutils-1.9.2.jar
- commons-collections-3.2.jar
- commons-digester-2.1.jar
- commons-logging-1.2.jar
- itext-2.1.7.jar
- jasperreports-5.6.0.jar
You can download from this link : https://drive.google.com/file/d/0B3BD2OiyeQ3UQWN2Nk82R1dhYmM/edit?usp=sharing
After download the .jar files, put those .jar file to the /lib folder. Then I use this code in my controller :
import net.sf.jasperreports.engine.JRException; import net.sf.jasperreports.engine.JRExporter; import net.sf.jasperreports.engine.JRExporterParameter; import net.sf.jasperreports.engine.JasperCompileManager; import net.sf.jasperreports.engine.JasperFillManager; import net.sf.jasperreports.engine.JasperPrint; import net.sf.jasperreports.engine.export.JRPdfExporter; class LabController { def dataSource def print() { try { String reportName, namaFile, dotJasper namaFile = "barang" reportName = grailsApplication.mainContext.getResource('reports/' + namaFile + '.jrxml').file.getAbsoluteFile() dotJasper = grailsApplication.mainContext.getResource('reports/' + namaFile + '.jasper').file.getAbsoluteFile() // Report parameter MapreportParam = new HashMap () // compiles jrxml JasperCompileManager.compileReportToFile(reportName); // fills compiled report with parameters and a connection JasperPrint print = JasperFillManager.fillReport(dotJasper, reportParam, dataSource.getConnection()); ByteArrayOutputStream pdfStream = new ByteArrayOutputStream(); // exports report to pdf JRExporter exporter = new JRPdfExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, print); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, pdfStream); // your output goes here exporter.exportReport(); } catch (Exception e) { throw new RuntimeException("It's not possible to generate the pdf report.", e); } finally { render(file: pdfStream.toByteArray(), contentType: 'application/pdf') } } }
Hi,
ReplyDeleteI am using grails 3.0.5 and include the jasper jar manually
compile('com.lowagie:itext:2.1.7')
compile ('net.sf.jasperreports:jasperreports:6.2.1')
I followed your sample code and run without error, but the only proboem is the gsp page shows blank pdf.
can i have a sample of the gsp code? thanks.
Blank pdf is good. Make sure the SQL query return some data with the given parameter.
DeleteHi , I am getting the following error. Please help. Thanks
DeleteURI
/jasReport/index
Class
groovy.lang.MissingPropertyException
Message
No such property: pdfStream for class: jasper2.JasReportController
This comment has been removed by the author.
ReplyDeletein grails 3.1.7 i can not integrate it ... is there any suggestion
ReplyDeleteSorry, I haven't tried grails 3.x yet
Deletemaybe you can try this https://javagrails.wordpress.com/2016/06/03/grails-3-jasper-integration/
DeleteStep 1 is a bit incorrect for my Grails 3.0.8. But the rest of the steps are all ok.
Hi, I am getting the following error. Please hep. Thanks.
DeleteURI
/jasReport/index
Class
groovy.lang.MissingPropertyException
Message
No such property: pdfStream for class: jasper2.JasReportController
thanks,
ReplyDeletefor grails 3.1.x
update build.gradle
repositories {
mavenCentral()
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
mavenCentral artifactUrls: [
'http://jasperreports.sourceforge.net/maven2',
'http://jaspersoft.artifactoryonline.com/jaspersoft/third-party-ce-artifacts/'
]
}
dependencies{
...
compile 'com.lowagie:itext:2.1.7'
compile 'net.sf.jasperreports:jasperreports:6.2.2'
}
Thanks... will be useful when upgrading my Grails
DeleteHi am new in grails. what will be gsp code for it? could you please
ReplyDeleteHi am new in grails. what will be gsp code for it? could you please
ReplyDeleteActually my problem is :
http://stackoverflow.com/questions/38493438/how-can-i-generate-jasper-report-in-grails-with-print-option
In grails 3.1.8 i can not integrate it. Is there any help or idea. Please help me.
ReplyDeleteHi, I am getting the following error. Please help. Thanks.
DeleteURI
/jasReport/index
Class
groovy.lang.MissingPropertyException
Message
No such property: pdfStream for class: jasper2.JasReportController