Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import net.sf.dynamicreports.jasper.builder.JasperReportBuilder;
- import net.sf.dynamicreports.report.builder.DynamicReports;
- import net.sf.dynamicreports.report.builder.column.Columns;
- import net.sf.dynamicreports.report.builder.component.Components;
- import net.sf.dynamicreports.report.builder.datatype.DataTypes;
- import net.sf.dynamicreports.report.builder.style.StyleBuilder;
- import net.sf.dynamicreports.report.constant.HorizontalAlignment;
- import net.sf.dynamicreports.report.exception.DRException;
- import java.awt.*;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import static net.sf.dynamicreports.report.builder.DynamicReports.cmp;
- public class FastReportTest {
- public static void main(String[] args) throws DRException {
- Connection connection = null;
- try {
- Class.forName("com.mysql.jdbc.Driver");
- connection = DriverManager.getConnection(
- "jdbc:mysql://localhost:3306/db1","root", "admin");
- } catch (SQLException e) {
- e.printStackTrace();
- return;
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- return;
- }
- JasperReportBuilder report = DynamicReports.report();//a new report
- StyleBuilder boldStyle = DynamicReports.stl.style().bold();
- StyleBuilder boldCenteredStyle = DynamicReports.stl.style(boldStyle)
- .setHorizontalAlignment(HorizontalAlignment.CENTER);
- StyleBuilder columnTitleStyle = DynamicReports.stl.style(boldCenteredStyle)
- .setBorder(DynamicReports.stl.pen1Point())
- .setBackgroundColor(Color.BLUE);
- StyleBuilder boldStyle1 = DynamicReports.stl.style().bold();
- StyleBuilder boldCenteredStyle1 = DynamicReports.stl.style(boldStyle).setHorizontalAlignment
- (HorizontalAlignment.CENTER);
- //BufferedImage img = new BufferedImage(1200,1200,BufferedImage.TYPE_INT_RGB);
- // BufferedImage img = null;
- // try {
- // // img = ImageIO.read(new File("D:/Hysteresis.png"));
- // img = ImageIO.read(new File("/home/anabil/Desktop/mapRouting3.png"));
- // } catch (IOException e) {
- // e.printStackTrace();
- // }
- // report.summary(cmp.image(img).setFixedDimension(500,500));
- // StyleBuilder style1 = Styles.style().setRadius(1000)
- // .setBackgroundColor(new Color(50, 230, 230))
- // .setLinePen(Styles.pen().setLineColor(Color.LIGHT_GRAY));
- //
- // ImageBuilder background1 = Components
- // .image(Templates.class
- // .getResource("/home/anabil/Desktop/mapRouting3.png")).setFixedDimension(500,500)
- // .setStyle(style1).setFixedDimension(500,500);
- //
- //
- // report.addBackground(background1);
- // report//create new report design
- // // .setColumnTitleStyle(boldStyle)
- // .setColumnStyle(boldStyle)
- // .highlightDetailEvenRows()
- // .summary(
- // cmp.verticalList()
- // .add(cmp.text("\n\nHYSTERISIS PLOT").setStyle(boldStyle))
- //
- // .add(cmp.image(img).setFixedDimension(500,500).) // Add the exported chart image to the report.
- // );
- report
- .setColumnTitleStyle(columnTitleStyle)
- .highlightDetailOddRows()
- .title(cmp.text("Getting started").setStyle(boldCenteredStyle));
- report
- .columns(
- Columns.column("first name", "firstname", DataTypes.stringType()),
- Columns.column("last name", "lastname", DataTypes.stringType()))
- .title(//title of the report
- Components.text("SimpleReportExample").setHorizontalAlignment(HorizontalAlignment.JUSTIFIED)
- )
- .pageFooter(Components.pageXofY())//show page number on the page footer
- .setDataSource("SELECT * FROM tb1",
- connection);
- try {
- //show the report
- report.show();
- //export the report to a pdf file
- report.toPdf(new FileOutputStream("/home/anabil/Desktop/report.pdf"));
- } catch (DRException e) {
- e.printStackTrace();
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement