Jump to content
Changes to the Jaspersoft community edition download ×

How do you add Image within JasperDesign?


2005 IR Help

Recommended Posts

By: Mark Simmons - bdmarr

How do you add Image within JasperDesign?

2004-05-28 12:16

I am not using xml, just java to generate report and need to add an image. How do you add an image to a band in java. I am using JasperDesign jasperDesign = new JasperDesign();, not the JasperPrint jasperPrint = new JasperPrint(); (which I see an example for). I must be missing something hopefuly very obvious.

 

 

 

 

By: Mathias Drischmann - mathiasd

RE: How do you add Image within JasperDesign?

2004-05-28 13:22

Hi Mark,

 

take a look at the source code of dori.jasper.engine.xml.JRImageFactory.

 

call ie. jasperDesign.get<band name>().addElement(...) to add it to the named band.

 

It may be necessary to create the band first.

 

best regards

 

Mathias

 

 

 

 

By: Mark Simmons - bdmarr

RE: How do you add Image within JasperDesign?

2004-05-28 13:33

OK, I have added this code to my program:

 

JRDesignImage image = new JRDesignImage();

image.setX(rptPageWidth-200);

image.setY(0);

image.setWidth(200);

image.setHeight(50);

image.setScaleImageJRImage.SCALE_IMAGE_CLIP);

 

band.addElement(image);

 

How do I set the actual image path/url/file name?

 

 

 

 

By: Mathias Drischmann - mathiasd

RE: How do you add Image within JasperDesign?

2004-06-01 00:35

Hi Mark,

 

create dori.jasper.engine.design.JRDesignExpression.

Use method setText of it to set image URL.

Set expr through method setExpression of JRDesignImage object.

 

A good place to look how to create design objects is the method dori.jasper.engine.xml.JRXmlLoader.prepareDigester().

It is responsible for creating a JasperDesign out of an XML file.

for each type of object their is a factory that is responsible for creating it.

Following lines may create / add / set dependent objects.

This depends on the XML tree structure.

 

 

 

 

By: Mark Simmons - bdmarr

RE: How do you add Image within JasperDesign?

2004-06-01 07:14

Mathias - thanks for all your help to date, looking through all the objects but not seeing it yet. You said to "setText of it to set image URL" - I put the file://... reference in as the text expression and it errors. I will try a relative image next..Keep you posted, thanks again..

 

 

 

 

By: Mark Simmons - bdmarr

RE: How do you add Image within JasperDesign?

2004-06-01 07:25

Solution / Solved....Thank you Mathias! Here is the code that appears to be working for me..

 

JRDesignImage image = new JRDesignImage();

image.setX(rptPageWidth-180-rptRightMargin);

image.setY(0);

image.setWidth(180);

image.setHeight(45);

image.setScaleImage(JRImage.SCALE_IMAGE_CLIP);

String absPath = ConstantManager.getProperty("AbsolutePath");

expression = new JRDesignExpression();

expression.setValueClass(java.lang.String.class);

expression.setText("""+"file:///" + absPath + File.separator + File.separator + "images" + File.separator + File.separator + "logo" + user.getCompanyId() + ".jpg" + """);

image.setExpression(expression);

band.addElement(image);

 

 

 

 

By: Mathias Drischmann - mathiasd

RE: How do you add Image within JasperDesign?

2004-06-01 07:33

Hi Mark,

 

I hope this little snippet will help you:

 

JRDesignImage image = new JRDesignImage();

JRDesignExpression expr = new JRDesignExpression();

expr.setText("images/myimage.gif");

image.setExpression(expr);

 

 

 

 

 

By: Mark Simmons - bdmarr

RE: How do you add Image within JasperDesign?

2004-06-01 07:40

Solution Part 2:

 

That worked for pdf, not html..

 

if (outputType.equals("pdf")) {

expression.setText("""+"file:///" + ConstantManager.getProperty("AbsolutePath") + File.separator + File.separator + "images" + File.separator + File.separator + "logo" + user.getCompanyId() + ".jpg" + """);

 

} else {

expression.setText("""+ConstantManager.getProperty("URLPath")+"/images/logo" + user.getCompanyId() + ".jpg" + """);

}

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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...