Advertisement
Guest User

Untitled

a guest
Oct 9th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.65 KB | None | 0 0
  1. import net.sf.dynamicreports.jasper.builder.JasperReportBuilder;
  2. import net.sf.dynamicreports.report.builder.DynamicReports;
  3. import net.sf.dynamicreports.report.builder.column.Columns;
  4. import net.sf.dynamicreports.report.builder.component.Components;
  5. import net.sf.dynamicreports.report.builder.datatype.DataTypes;
  6. import net.sf.dynamicreports.report.builder.style.StyleBuilder;
  7. import net.sf.dynamicreports.report.constant.HorizontalAlignment;
  8. import net.sf.dynamicreports.report.exception.DRException;
  9.  
  10. import java.awt.*;
  11. import java.io.FileNotFoundException;
  12. import java.io.FileOutputStream;
  13. import java.sql.Connection;
  14. import java.sql.DriverManager;
  15. import java.sql.SQLException;
  16.  
  17. import static net.sf.dynamicreports.report.builder.DynamicReports.cmp;
  18.  
  19.  
  20. public class FastReportTest {
  21.  
  22. public static void main(String[] args) throws DRException {
  23. Connection connection = null;
  24. try {
  25. Class.forName("com.mysql.jdbc.Driver");
  26. connection = DriverManager.getConnection(
  27. "jdbc:mysql://localhost:3306/db1","root", "admin");
  28. } catch (SQLException e) {
  29. e.printStackTrace();
  30. return;
  31. } catch (ClassNotFoundException e) {
  32. e.printStackTrace();
  33. return;
  34. }
  35.  
  36. JasperReportBuilder report = DynamicReports.report();//a new report
  37.  
  38. StyleBuilder boldStyle = DynamicReports.stl.style().bold();
  39.  
  40. StyleBuilder boldCenteredStyle = DynamicReports.stl.style(boldStyle)
  41.  
  42. .setHorizontalAlignment(HorizontalAlignment.CENTER);
  43.  
  44. StyleBuilder columnTitleStyle = DynamicReports.stl.style(boldCenteredStyle)
  45.  
  46. .setBorder(DynamicReports.stl.pen1Point())
  47.  
  48. .setBackgroundColor(Color.BLUE);
  49.  
  50.  
  51. StyleBuilder boldStyle1 = DynamicReports.stl.style().bold();
  52. StyleBuilder boldCenteredStyle1 = DynamicReports.stl.style(boldStyle).setHorizontalAlignment
  53. (HorizontalAlignment.CENTER);
  54. //BufferedImage img = new BufferedImage(1200,1200,BufferedImage.TYPE_INT_RGB);
  55. // BufferedImage img = null;
  56. // try {
  57. // // img = ImageIO.read(new File("D:/Hysteresis.png"));
  58. // img = ImageIO.read(new File("/home/anabil/Desktop/mapRouting3.png"));
  59. // } catch (IOException e) {
  60. // e.printStackTrace();
  61. // }
  62.  
  63. // report.summary(cmp.image(img).setFixedDimension(500,500));
  64.  
  65. // StyleBuilder style1 = Styles.style().setRadius(1000)
  66. // .setBackgroundColor(new Color(50, 230, 230))
  67. // .setLinePen(Styles.pen().setLineColor(Color.LIGHT_GRAY));
  68. //
  69. // ImageBuilder background1 = Components
  70. // .image(Templates.class
  71. // .getResource("/home/anabil/Desktop/mapRouting3.png")).setFixedDimension(500,500)
  72. // .setStyle(style1).setFixedDimension(500,500);
  73. //
  74. //
  75. // report.addBackground(background1);
  76. // report//create new report design
  77. // // .setColumnTitleStyle(boldStyle)
  78. // .setColumnStyle(boldStyle)
  79. // .highlightDetailEvenRows()
  80. // .summary(
  81. // cmp.verticalList()
  82. // .add(cmp.text("\n\nHYSTERISIS PLOT").setStyle(boldStyle))
  83. //
  84. // .add(cmp.image(img).setFixedDimension(500,500).) // Add the exported chart image to the report.
  85. // );
  86.  
  87.  
  88. report
  89. .setColumnTitleStyle(columnTitleStyle)
  90.  
  91. .highlightDetailOddRows()
  92.  
  93. .title(cmp.text("Getting started").setStyle(boldCenteredStyle));
  94.  
  95.  
  96.  
  97. report
  98. .columns(
  99. Columns.column("first name", "firstname", DataTypes.stringType()),
  100. Columns.column("last name", "lastname", DataTypes.stringType()))
  101. .title(//title of the report
  102. Components.text("SimpleReportExample").setHorizontalAlignment(HorizontalAlignment.JUSTIFIED)
  103. )
  104. .pageFooter(Components.pageXofY())//show page number on the page footer
  105. .setDataSource("SELECT * FROM tb1",
  106. connection);
  107.  
  108.  
  109.  
  110. try {
  111. //show the report
  112. report.show();
  113.  
  114. //export the report to a pdf file
  115. report.toPdf(new FileOutputStream("/home/anabil/Desktop/report.pdf"));
  116. } catch (DRException e) {
  117. e.printStackTrace();
  118. } catch (FileNotFoundException e) {
  119. e.printStackTrace();
  120. }
  121.  
  122.  
  123. }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement