BIRT的HTMLRenderReport向嵌入的图像中添加了一个类似于file://的url(而不是将其嵌入到HTML中) [英] HTMLRenderReport of BIRT adds a `file://`-like url to embedded images (instead of embedding them into the HTML)
问题描述
我有一个BIRT报告,其主页上有一个图像.
I have a BIRT report with an image in the master page.
我在报告中嵌入了png,并在body
标记后生成了以下XML:
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>
我的BIRT设计文件的行为:
然后,如果我从BIRT设计器运行预览,则HTML和PDF输出都可以很好地工作.如果我使用IPDFRenderOption
渲染(来自我的软件),它将生成正确的pdf
罚款. 但是,如果我使用HTMLRenderOption
,则图像不会嵌入到HTML报告中,而是使用类似以下内容的图像呈现:
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 ">
那么,当用HTMLRenderOption
执行时,如何让BIRT将图像嵌入到HTML文件中,而不是创建指向该文件的链接?
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?
推荐答案
我通过向报表的主页添加两个不同的图像来解决了这个问题:
I solved this by adding two different images to the masterpage of the report:
由于PDF
的渲染效果很好,所以我将图像保留为在问题中所写的位置,并在HTML输出中设置了该图像的可见性
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
然后,在母版页中,添加了一个新图像.这次我没有将其设置为嵌入式.相反,我将其设置为由URI
引用.作为URI
,我在HTML
输出中设置了所需的base64 URI
.基本上,我在报告的XML
中添加了以下图像:
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>
然后我将图像设置为仅对HTML
输出可见.
I then set the image to be visibile only for the HTML
output.
以这种方式BIRT
渲染一个img
标签,其中包含我放置在XML
中的URL
,无论它是什么.因此,将data:image/png;base64, BASE 64 OF MY PNG IMAGE
放置为url
.从而将图像嵌入到HTML
输出中.
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.
BIRT支持blob
字段中的图像,并且可以将其添加到报告中.要查看操作方法,请参见:
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
如果它不起作用,您可以管理在url上插入动态值,而无需编辑脚本(但是当然要使用一点Javascript来确定哪一列包含了图像数据).
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).
下面是从列中读取base64
值的图像的XML代码:
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>
这篇关于BIRT的HTMLRenderReport向嵌入的图像中添加了一个类似于file://的url(而不是将其嵌入到HTML中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!