Last active
September 27, 2019 13:39
-
-
Save osmanizbat/4451128 to your computer and use it in GitHub Desktop.
Groovier reports with groovy & jasperreports
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.awt.Color; | |
| import net.sf.jasperreports.engine.*; | |
| import net.sf.jasperreports.engine.design.*; | |
| import net.sf.jasperreports.engine.type.*; | |
| import net.sf.jasperreports.view.JasperViewer | |
| class GroovierReport { | |
| static void main(String[] args) { | |
| def builder = new ObjectGraphBuilder() | |
| builder.classNameResolver = "net.sf.jasperreports.engine.design" | |
| def jasperDesign = builder.jasperDesign( | |
| name : "GroovierReport", | |
| columnCount : 1, | |
| pageWidth : 612, | |
| pageHeight : 792, | |
| columnWidth : 562, | |
| columnSpacing : 0, | |
| leftMargin : 30, | |
| rightMargin : 20, | |
| topMargin : 30, | |
| bottomMargin : 30, | |
| whenNoDataType : WhenNoDataTypeEnum.ALL_SECTIONS_NO_DETAIL, | |
| titleNewPage : Boolean.FALSE, | |
| summaryNewPage : Boolean.FALSE, | |
| ) | |
| def titleStyle = builder.jRDesignStyle( | |
| name : "titleStyle", | |
| fontName : "Arial", | |
| forecolor : Color.BLUE, | |
| fontSize : 20, | |
| bold : true, | |
| italic : false, | |
| underline : false, | |
| strikeThrough : false, | |
| pdfEmbedded : true, | |
| ) | |
| jasperDesign.addStyle(titleStyle); | |
| def titleBand = builder.jRDesignBand(height: 50) | |
| def textField = builder.jRDesignTextField( | |
| stretchWithOverflow: true, | |
| blankWhenNull: true, | |
| style: titleStyle, | |
| x: 10, | |
| y: 10, | |
| width: 200, | |
| height: 13, | |
| key: "titleTextField", | |
| ) | |
| def expression=new JRDesignExpression(); | |
| expression.setValueClass(String.class); | |
| expression.setText("\"Hello world!\""); | |
| textField.setExpression(expression); | |
| textField.getLineBox().setPadding(1); | |
| textField.getLineBox().getPen().setLineWidth(0); | |
| textField.getLineBox().getPen().setLineColor(Color.BLACK); | |
| titleBand.addElement(textField); | |
| jasperDesign.setTitle(titleBand); | |
| def jasperReport = JasperCompileManager.compileReport(jasperDesign); | |
| def jasperPrint = JasperFillManager.fillReport(jasperReport, new HashMap()); | |
| JasperViewer.viewReport(jasperPrint); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment