How to set margins in a subreport using DynamicReports?

44 Views Asked by At

The problem is that the subreport gets the margins of the parent report. The sub report contains an ImageBuilder, which builds an image of a static PDF-file. This image is placed between the header and footer from the parent report. I first set these margins in the parent report:

final MarginBuilder PAGE_MARGIN = margin(20).setLeft(50).setRight(90).setBottom(15).setTop(40);
reportBuilder.setPageMargin(PAGE_MARGIN);

I then try to set small margins in the sub report with MarginBuilder, but it does not work. How can I make this work, so the subreport does not get the same margins as the parent report? Here is my code for the sub report:

private void createImage(final JasperReportBuilder parentReportBuilder, byte[] contentOfStaticPDF) {
    JasperReportBuilder reportBuilderForSubreport = report();
    final int PAGE_WIDTH = 450;
    ImageBuilder imageBuilder = cmp.image(getContentAsInputStream(contentOfStaticPDF));
    imageBuilder.setFixedWidth(PAGE_WIDTH);
    imageBuilder.setStretchType(StretchType.CONTAINER_HEIGHT);
    MarginBuilder marginBuilder= margin();
    int margin=1;
    marginBuilder.setLeft(margin);
    marginBuilder.setRight(margin);
    reportBuilderForSubreport.setPageMargin(marginBuilder);
    reportBuilderForSubreport.detail(imageBuilder);
    reportBuilderForSubreport.detail(cmp.pageBreak());
    SubreportBuilder subreport = cmp.subreport(reportBuilderForSubreport).setDataSource(createFakeDataSource());
    parentReportBuilder.detail(subreport);
}
0

There are 0 best solutions below