作者:Ricardo Mariaca。此代碼是解決,感謝里卡多和動態報告
private void build() {
try {
JasperPdfExporterBuilder pdfExporterBuilder = export
.pdfExporter(PDF_FILE);
JasperReportBuilder jasperReportBuilderMain = report()
.columns(
col.column("Item", "item", type.stringType()),
col.column("Quantity", "quantity",
type.integerType()),
col.column("Unit price", "unitprice",
type.bigDecimalType()))
.setDataSource(createSubreportDataSource())
// .detail(cmp.subreport(createSubreport()))
.setWhenNoDataType(WhenNoDataType.ALL_SECTIONS_NO_DETAIL);
JasperReportBuilder jasperReportBuilderDisclaimer = report()
.setPageFormat(PageType.A4, PageOrientation.LANDSCAPE)
.summary(cmp.subreport(jasperReportBuilderMain))
.summaryWithPageHeaderAndFooter()
.setWhenNoDataType(WhenNoDataType.ALL_SECTIONS_NO_DETAIL)
.columnHeader(
cmp.text("first page header").setFixedHeight(50))
.columnFooter(
cmp.text(DISCLAIMER).setStretchWithOverflow(true)
.setFixedHeight(250))
.pageHeader(
Templates
.createTitleComponent("Ricardo Mariaca Approach"))
.pageFooter(Templates.footerComponent).show()
.toPdf(pdfExporterBuilder);
} catch (DRException e) {
e.printStackTrace();
}
}
private JRDataSource createSubreportDataSource() {
DRDataSource dataSource = new DRDataSource("item", "quantity",
"unitprice");
for (int i = 0; i < 180; i++) {
dataSource.add("Book", (int) (Math.random() * 10) + 1,
new BigDecimal(Math.random() * 100 + 1));
}
return dataSource;
}
}
我知道的JasperReport文檔說:_Stretching高度元素可以被管理得非常好,由於部分分裂設施:除了極少數例外(即列和頁腳)_。我正在尋找其他解決方案 –