I have a report developed in Java that uses DynamicReports. When I try to generate a report with more than 1000 pages approximately the system launches a Java Heap Exception. Is there any way to subdivide into smaller reports by Dynamic Reports itself? For example: loading only 100 pages at a time, then 100 more, and so on?
Below is a very generic code that represents a situation where this error occurs.
public class EncryptedPdfReport {
public EncryptedPdfReport() {
build();
}
private void build() {
try {
JasperPdfExporterBuilder pdfExporter = export.pdfExporter("c:/report.pdf")
.setEncrypted(true)
.setUserPassword("1234");
report()
.setTemplate(Templates.reportTemplate)
.columns(
col.column("Item", "item", type.stringType()),
col.column("Quantity", "quantity", type.integerType()),
col.column("Unit price", "unitprice", type.bigDecimalType()))
.title(Templates.createTitleComponent("EncryptedPdfReport"))
.pageFooter(Templates.footerComponent)
.setDataSource(createDataSource())//exceção acontece //quando esse metodo é chamado
.toPdf(pdfExporter);
} catch (DRException e) {
e.printStackTrace();
}
}
private JRDataSource createDataSource() {
DRDataSource dataSource = new DRDataSource("item", "quantity", "unitprice");
//na linha de baixo estou inserindo uma grande quantidade de dados na //datasource.
for (int i = 0; i < 2000000000; i++) {
dataSource.add("Book", (int) (Math.random() * 10) + 1, new BigDecimal(Math.random() * 100 + 1));
}
return dataSource;
}
public static void main(String[] args) {
new EncryptedPdfReport();
}
}