Jump to content
We've recently updated our Privacy Statement, available here ×

How can I use setFixedHeight and setPageMargin in ImageBuilder?


eyvind.almqvist

Recommended Posts

I am including an image at the end of a report. It is an image of a PDF-file. The image gets a blurry resolution, because I can not make it bigger and I can not make the margins smaller. 

I try to increase the width with  this:

imageBuilder.setFixedWidth(PAGE_WIDTH);
But if I set the width over 440, the image is not shown at all. I don't why, because the value 440 does not appear anywhere in my project. 

I try to make the margins smaller with this:

jasperReportBuilder.setPageMargin(margin().setLeft(0).setRight(0).setBottom(0).setTop(0));
but large margins are still shown around the image. I attached a picture of how it looks like. How can I set higher width on the image and set lower margins? This is all my relevant code:

private void createImage(final JasperReportBuilder reportBuilder, byte[] content) {
JasperReportBuilder jasperReportBuilder = report();
ImageBuilder imageBuilder=cmp.image(getContentAsInputStream(content));
imageBuilder.setFixedHeight(PAGE_HEIGHT);
imageBuilder.setFixedWidth(PAGE_WIDTH);
imageBuilder.setStretchType(StretchType.CONTAINER_HEIGHT);
jasperReportBuilder.detail(imageBuilder);
jasperReportBuilder.detail(cmp.pageBreak());
jasperReportBuilder.setPageMargin(margin().setLeft(0).setRight(0).setBottom(0).setTop(0));

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Try this format

private void createImage(final JasperReportBuilder reportBuilder, byte[] content) {
    JasperReportBuilder jasperReportBuilder = report();
    
    // Adjust the values according to your requirements
    int PAGE_HEIGHT = 100; // Set the desired height
    int PAGE_WIDTH = 600; // Set the desired width

    ImageBuilder imageBuilder = cmp.image(getContentAsInputStream(content));
    imageBuilder.setFixedHeight(PAGE_HEIGHT);
    imageBuilder.setFixedWidth(PAGE_WIDTH);
    imageBuilder.setStretchType(StretchType.CONTAINER_HEIGHT);
    
    jasperReportBuilder.setPageMargin(margin().setLeft(0).setRight(0).setBottom(0).setTop(0));

    // Add the image to the report
    jasperReportBuilder.detail(imageBuilder);
    jasperReportBuilder.detail(cmp.pageBreak());
}

 

Set the fixed height and page margins in the ImageBuilder.

 

Link to comment
Share on other sites

 

rsneha027, I tested your solution. The only difference in it is that   jasperReportBuilder.setPageMargin(margin().setLeft(0).setRight(0).setBottom(0).setTop(0));

is called before 

 jasperReportBuilder.detail()

But it is the same problem. The subreport gets the margin of the parent report and the margin I set in the image builder makes no difference. I still can not set the width of the image over a certain value. If I do that, the image is not shown. How can I solve this? This is my new code:

    private void createImage(final JasperReportBuilder reportBuilder, byte[] content) {       //the subreport:        JasperReportBuilder jasperReportBuilder = report();        final int PAGE_WIDTH = 455;         //set up an imagebuilder:        ImageBuilder imageBuilder = cmp.image(getContentAsInputStream(content));        imageBuilder.setFixedWidth(PAGE_WIDTH);        imageBuilder.setStretchType(StretchType.CONTAINER_HEIGHT);//needs to be there, otherwise  the picture gets very small        imageBuilder.setHorizontalImageAlignment(HorizontalImageAlignment.LEFT);        imageBuilder.setImageScale(ImageScale.FILL_FRAME);        jasperReportBuilder.setPageMargin(margin().setLeft(0).setRight(0).setBottom(0).setTop(0));        //Adds components to the detail band :        jasperReportBuilder.detail(imageBuilder);        jasperReportBuilder.detail(cmp.pageBreak());//needs to be there, otherwise  the picture gets very small     //add subreport to the parent report:        //creates a a SubreportBuilder from a JasperReportBuilder        SubreportBuilder subreport = cmp.subreport(jasperReportBuilder).setDataSource(createFakeDataSource());      //add subreport to report :        reportBuilder.detail(subreport);    }

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...