Dynamic printing Jasperreports

Asked

Viewed 423 times

1

I’m trying to make an impression with JasperReports, when compiling the report I get the following error:

Exception in thread "main"
net.sf.jasperreports.engine.design.Jrvalidationexception: Report
design not Valid :
1. The Columns and the margins do not fit the page width.
2. The background Section and the margins do not fit the page height.
3. The title Section, the page and column headers and footers and the margins do not fit the page height.
4. The page and column headers and footers and the margins do not fit the page height.
5. The page and column headers and footers and the margins do not fit the last page height.
6. The Summary Section and the margins do not fit the page height.
7. The Detail Section, the page and column headers and footers and the margins do not fit the page height.
8. The noData Section and the margins do not fit the page height. at net.sf.jasperreports.engine.design.JRAbstractCompiler.verifyDesign(Jrabstractcompiler.java:271) at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(Jrabstractcompiler.java:153) at net.sf.jasperreports.engine.Jaspercompilemanager.Compile(Jaspercompilemanager.java:241) at net.sf.jasperreports.engine.Jaspercompilemanager.compileReport(Jaspercompilemanager.java:501) Print(Print this page.java:49)

Below is the test code :

JasperDesign report = new JasperDesign();
report.setName("teste");
report.setPageWidth(90);
report.setPageHeight(45);

JRDesignBand band = new JRDesignBand();
band.setHeight(45);

JRDesignStaticText text = new JRDesignStaticText();
text.setText("Primeira impressão");
text.setHeight(20);
text.setWidth(60);
text.setX(1);
text.setY(1);
band.addElement(text);

((JRDesignSection)report.getDetailSection()).addBand(band);

JasperReport relatorio = JasperCompileManager.compileReport(report); //Aqui ocorre o erro

JasperPrint print = JasperFillManager.fillReport(relatorio, new HashMap<>());
JasperViewer jrviewer = new JasperViewer(print, false);
jrviewer.setVisible(true);
  • Have you tried using Jaspersoft studio or iReport to make your report? all errors are related to insufficient section size.

  • @Gustavofragoso, I can’t do it for iReport because the form will be customized by the user. It will add the fields and values of each field.

1 answer

1


I found the problem, it seems that the JasperReports is lost when it does not have the margins set, so I set the margins, another problem is that it also can not generate the report without a DataSource, to solve this problem I spent a JREmptyDataSource, the code stayed this way:

JasperDesign report = new JasperDesign();
report.setName("teste");
report.setPageWidth(90);
report.setPageHeight(45);
report.setBottomMargin(0);
report.setTopMargin(0);
report.setLeftMargin(0);
report.setRightMargin(0);
report.setColumnWidth(89);

JRDesignBand band = new JRDesignBand();
band.setHeight(45);

JRDesignStaticText text = new JRDesignStaticText();
text.setText("Primeira impressão");
text.setHeight(20);
text.setWidth(60);
text.setX(1);
text.setY(1);
band.addElement(text);

((JRDesignSection)report.getDetailSection()).addBand(band);

JasperReport relatorio = JasperCompileManager.compileReport(report);

JasperPrint print = JasperFillManager.fillReport(relatorio, new HashMap<>(), new JREmptyDataSource(1));
print.setPageHeight(report.getPageHeight());
print.setPageWidth(report.getPageWidth());
print.setBottomMargin(report.getBottomMargin());
print.setTopMargin(report.getTopMargin());
print.setLeftMargin(report.getLeftMargin());
print.setRightMargin(report.getRightMargin());

JasperViewer jrviewer = new JasperViewer(print, false);
jrviewer.setVisible(true);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.