问题
I have a BIRT report with an image in the master page.
My BIRT design file:
I embedded a png inside the report and it generated the following XML after the body
tag:
<list-property name="images">
<structure>
<property name="name">filename.png</property>
<property name="type">image/png</property>
<property name="data">
BASE64 of the image
</property>
</structure>
</list-property>
Then, I have included it into the master page, adding this element:
<image id="828">
<property name="source">embed</property>
<property name="imageName">filename.png</property>
</image>
Behaviours of my BIRT design file:
Then, If I run the preview from the BIRT designer it works great with both HTML and PDF output. If I render it using IPDFRenderOption
(from my software) it generates the correct pdf
fine. But if I use HTMLRenderOption
, then the image is not embeded into the HTML report, but it is rendered with something like:
<img src="file:/.../apache-tomcat-7.0.35/design11.png">
What I expect:
While I expected something like:
<img src="data:image/png;base64,BASE64 STUFF THAT I PUT IN THE LIST-PROPERTIES ">
So, how can I let BIRT, when executed with HTMLRenderOption
, to embed my image into the HTML file instead of creating a link to it?
回答1:
I solved this by adding two different images to the masterpage of the report:
Setting of the image in the PDF output:
Since the PDF
is well rendered, I leaved the image as I wrote in the question, and I set off the visibility of this image in the HTML output
Setting of the image in the HTML output:
Then, in the master page, I added a new image. This time I haven't set it as embedded. Instead I set it as referenced by an URI
. As URI
I set the base64 URI
that I need in my HTML
output. Basically, I added to the XML
of the report the following image:
<image id="1972">
<list-property name="visibility">
<structure>
<property name="format">pdf</property>
<expression name="valueExpr" type="javascript">true</expression>
</structure>
</list-property>
<property name="source">url</property>
<expression name="uri" type="constant">data:image/png;base64, BASE 64 OF MY PNG IMAGE</expression>
</image>
I then set the image to be visibile only for the HTML
output.
In this way BIRT
renders an img
tag with the URL
i put in the XML
, whatever it is. And thus, it puts the data:image/png;base64, BASE 64 OF MY PNG IMAGE
as url
. And thus it embeds the image in the HTML
output.
Adding images from the database in your table:
BIRT supports the images inside blob
fiels, and can manage in adding them to your report. To see how, see there: http://help.eclipse.org/helios/index.jsp?topic=%2Forg.eclipse.birt.doc%2Fbirt%2Flayout.5.7.html
If it does not works, you can manage inserting a dynamic value on your url, still without editing the scripts (but of course using a bit of Javascript to decide which column contains the data of teh image).
Here below the XML code of an image that reads the base64
value from a column:
<image id="1974">
<property name="source">url</property>
<expression name="uri" type="javascript">"data:image/png;base64,"+row["BASE_64_PNG_COLUMN"] </expression>
</image>
来源:https://stackoverflow.com/questions/24308980/htmlrenderreport-of-birt-adds-a-file-like-url-to-embedded-images-instead-o