Jump to content

Images at Runtime


markrgli

Recommended Posts

Hi guys,

Is it possible to set the image path/data of a report (from a .jrxml file) at runtime?

I have these JRXML files that have image placeholders (there are image elements in the design file but the expressions are not set) and I need to set the path/data of the image from my code after I load the design file. Is this possible? Attached is the code I tried but apparently it didn't work.

Any ideas?

Thank you in advance.

Mark

Code:
JasperDesign design = JRXmlLoader.load(jasperFile);			JRElement elem = design.getDetail().getElementByKey("banner");if (elem instanceof JRDesignImage) {	JRDesignImage img = (JRDesignImage) elem;	        // Tried debugging and confirmed that this line is called.	img.setExpression(new JRDesignExpression() {		private static final long serialVersionUID = 1L;				@Override		public String getText() {			return "D:\\images\\sample.jpg";		}				@Override		public Class getValueClass() {			return String.class;		}				@Override		public String getValueClassName() {			return String.class.getName();		}			});}
Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

I've found the solution. :)

Hope it will be of any help to others.

Code:
JasperDesign design = // load designJRBand band = design.getDetail();// "banner" is the key of the image "placeholder" in my design fileJRElement elem = band == null ? null : band.getElementByKey("banner");if (elem instanceof JRDesignImage) {	JRDesignImage img = (JRDesignImage) elem;	JRDesignExpression expr = new JRDesignExpression();	expr.setText("\"D:/images/sample.jpg\"");	expr.setValueClass(String.class);	expr.setValueClassName(String.class.getName());		img.setExpression(expr);}
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...