我想将图片包含在BIRT报告中。图像应由XML数据源(base64编码)给出。但XML数据源不支持Blob数据类型。
我在this BIRT question找到了一个很好的答案,其中base64编码的图像数据包含在URI(getName()
)中。所以我尝试了一个小的静态示例,但BIRT(4.4.2)没有显示图像。当我将URI粘贴到地址栏时,Firefox会显示图像。
这是一个重现问题的小型静态BIRT测试报告。
data:image/png;base64,...BASE64DATA...
更新 生成的HTML中的img标记看起来像
<?xml version="1.0" encoding="UTF-8"?>
<report xmlns="http://www.eclipse.org/birt/2005/design" version="3.2.23" id="1">
<property name="createdBy">Eclipse BIRT Designer Version 4.4.2.v201410272105 Build <4.4.2.v20150217-1805></property>
<property name="units">in</property>
<property name="iconFile">/templates/blank_report.gif</property>
<property name="bidiLayoutOrientation">ltr</property>
<property name="imageDPI">96</property>
<styles>
</styles>
<page-setup>
<simple-master-page name="Simple MasterPage" id="2">
</simple-master-page>
</page-setup>
<body>
<image id="7">
<property name="source">url</property>
<expression name="uri" type="constant">data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAIAAAC0tAIdAAAACXBIWXMAAAsTAAALEwEAmpwYAAACa0lEQVR4nE2SW0iTYQCG3+/bv4Pb3GqeJuWcadJJ1Lww1KiLKUbZQSzCwJCiLotu6yYIvPAyiIRIDDITUdO0VQZFKAaTLMPpdLL9rKlNnbr57/Tv+7rQyOf6uXjhfQjnHAAAzvl7+/CSdxzxJSkU0Or0UGXvL6y22WrwD7Jti6I41P3o/Kn0fTkHQLXgcSQCiPk8C85hh7G++bHZbN6xvV7PaP+dxgvHoMmHxgJhD5ISYj5E3Yi4ILnah2JnbtrNZjNljL3rvNtYawBNgUIPIR2aPKiyIRhAtSBqUGWzbbnv2Q0AirLSozX5b9Uppo5h6fu8IIr+Q4V5YOEl/8KLQf/U4kHnzExRzkpmitfhK6Zr7q4MY7zv0++iylbnXAVXV/xw2BH1fPjiLDhy781gpsrSMifGc83UN/2Kkq0JyJuxmCyKQk/PV0HIWlucQsRF5NVwmITDKiCqFAAAoQnFpZO8uIBlm6Lj0+LZiyUBd1v9aYHKgdy01W8T9tKSqG615cThGIDRySDpeJjTVC0BhFOtJBt1eiOIElxGMgw5iGQY2DmkfSRDYNoSYAzghG3pqITICggFGJgMMOyCpJZRg/VyMMQB/HQnAQ4eB4uCxbfVeAJPeqMc8K+wrMIrJJFIPG+pumWbF5dZ68tIea7CbFGoVWR9gwVnZLs32XZfn6olT0eKbz8YIZxzl2v210BtfWUoJPH+19HIWFxe54Y0KlQp6xo0Og3p/JxWde2jxWLZ6cTlmv3cdb2hfM5kILu3/gmyXkdRbVOH1Wr9XxUAWZYH+rs2Pd1UmoS8AWEv0x03FVw9V9dAKd12/gIfwCYkqvTc3gAAAABJRU5ErkJggg==</expression>
</image>
</body>
</report>
所以问题似乎是BIRT将<img ... src="/viewer/data:image/png;base64,......"></img>
添加到URI。
是否有任何配置,以便BIRT不向报告中定义的URI添加任何内容?
答案 0 :(得分:3)
使用数据URI是一种解决方法。您只需将嵌入式BASE64编码数据用于静态图像:
<report>
<body>
<image id="7">
<property name="source">embed</property>
<property name="imageName">some.png</property>
</image>
</body>
<list-property name="images">
<structure>
<property name="name">some.png</property>
<property name="type">image/png</property>
<property name="data">iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAIAAAC0tAIdAAAACXBIWXMAAAsTAAALEwEAmpwYAAACa0lEQVR4nE2SW0iTYQCG3+/bv4Pb3GqeJuWcadJJ1Lww1KiLKUbZQSzCwJCiLotu6yYIvPAyiIRIDDITUdO0VQZFKAaTLMPpdLL9rKlNnbr57/Tv+7rQyOf6uXjhfQjnHAAAzvl7+/CSdxzxJSkU0Or0UGXvL6y22WrwD7Jti6I41P3o/Kn0fTkHQLXgcSQCiPk8C85hh7G++bHZbN6xvV7PaP+dxgvHoMmHxgJhD5ISYj5E3Yi4ILnah2JnbtrNZjNljL3rvNtYawBNgUIPIR2aPKiyIRhAtSBqUGWzbbnv2Q0AirLSozX5b9Uppo5h6fu8IIr+Q4V5YOEl/8KLQf/U4kHnzExRzkpmitfhK6Zr7q4MY7zv0++iylbnXAVXV/xw2BH1fPjiLDhy781gpsrSMifGc83UN/2Kkq0JyJuxmCyKQk/PV0HIWlucQsRF5NVwmITDKiCqFAAAoQnFpZO8uIBlm6Lj0+LZiyUBd1v9aYHKgdy01W8T9tKSqG615cThGIDRySDpeJjTVC0BhFOtJBt1eiOIElxGMgw5iGQY2DmkfSRDYNoSYAzghG3pqITICggFGJgMMOyCpJZRg/VyMMQB/HQnAQ4eB4uCxbfVeAJPeqMc8K+wrMIrJJFIPG+pumWbF5dZ68tIea7CbFGoVWR9gwVnZLs32XZfn6olT0eKbz8YIZxzl2v210BtfWUoJPH+19HIWFxe54Y0KlQp6xo0Og3p/JxWde2jxWLZ6cTlmv3cdb2hfM5kILu3/gmyXkdRbVOH1Wr9XxUAWZYH+rs2Pd1UmoS8AWEv0x03FVw9V9dAKd12/gIfwCYkqvTc3gAAAABJRU5ErkJggg==</property>
</structure>
</list-property>
</report>
或以下javascript表达式在渲染时解码BASE64编码变量:
<report>
<body>
<image id="7">
<property name="source">expr</property>
<expression name="valueExpr" type="javascript">org.apache.commons.codec.binary.Base64.decodeBase64(base64EncodedStringOfImage)</expression>
</image>
</body>
</report>