Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Setting Image on Runtime
kosta
Hello BIRT community,<br />
<br />
I have an image item in one grid and it has name.<br />
I can load it in an ItemHanle via the BIRT API.<br />
The image item is an dummy item with height and width 0 pixels and is empty and unvisible.<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
<image name="myName" id="1869">
<property name="height">0mm</property>
<property name="width">0mm</property>
<list-property name="visibility">
<structure>
<property name="format">all</property>
<expression name="valueExpr" type="javascript">true</expression>
</structure>
</list-property>
<property name="source">file</property>
<expression name="uri" type="javascript">test</expression>
</image>
</pre>
<br />
How can I fill it vie the BIRT API with path in the javascript expression and set the image visible?<br />
I know how to set the Height and Width.<br />
<br />
For any hints and suggestions thanks in advance.
Find more posts tagged with
Comments
JasonW
Kosta,
Are you wanting to set the uri from RE API?
Jason
kosta
Yes, not only the uri but also setting the image item to visible vie the RE API.<br />
<br />
I m trying to do that with:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
String puttingImagePath = "someStaticPath";
Expression myexpression = new Expression(puttingImagePath, ExpressionType.JAVASCRIPT);
imageHandle.setExpressionProperty(ExpressionPropertyType.URI_TYPE_NAME, myexpression);
</pre>
<br />
Abut setting visibility I only found a final static fiels VISIBILITY_PROP or a method visibilityRulesIterator which gives Iterator as return value.<br />
The is obvious a constant that has the value "visibility".<br />
<br />
While I was writing this message I have tested something like:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
Iterator iter = imageHandle.visibilityRulesIterator();
System.out.println("iter.hasNext(): " + iter.hasNext());
while(iter.hasNext()) {
Object obj = iter.next();
if(obj instanceof HideRuleHandle) {
HideRuleHandle hideRuleHandle = (HideRuleHandle)obj;
Expression hideExpression = new Expression(Boolean.toString(false), ExpressionType.JAVASCRIPT);
hideRuleHandle.setExpressionProperty("valueExpr", hideExpression);
}
}
</pre>
and it worked.<br />
<br />
I can see the image in the PDF.<br />
Thanks
kosta
Is it possible to pass a image stream to the ImageHandle or BIRT generally somehow or must the image be on the filesystem?
JasonW
You could probably pass an image byte array into appcontext and in script use it to render an image.
Jason
kosta
Hi Jason,
how can I use script to render an image ?
Thanks for any hints and suggestions.
JasonW
Kosta
Look at this post.
http://birtworld.blogspot.com/2010/09/birt-image-report-item.html
You can always set an images bytes by using this.data = bytearray.
Jason
kosta
Thank you for the answer Jason.
what about when I am using an <img>-Tag in a text report item. Can I use some variables or desriptions that refer to an binary object?
Thanks in advance.
JasonW
Kosta,
You can always re-write a text expression in an oncreate event, but if you have your image in a byte array the only way I know to include it in a text element with img tag is to base64 encode it and inline the image. See attached example.
Jason
kosta
Hello Jason,
This works when the report is exported as HTML. When exporting to PDF the sources are not reachable.
It that a normal behauviour?
Thanks for answers and suggestions.
JasonW
That is correct.
Jason