BIRT不显示base64编码的图像

BIRT不显示base64编码的图像

本文介绍了BIRT不显示base64编码的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将图像包含在BIRT报告中.图像应由XML数据源(base64编码)给出.但是XML数据源不支持Blob数据类型.

I want to include images into a BIRT report. The images shall be given by a XML data source (base64 encoded). But the XML data source does not support the Blob data type.

我在,其中将base64编码的图像数据作为URI()包括在内.因此,我尝试了一个小的静态示例,但BIRT(4.4.2)没有显示图像.当我将URI粘贴到地址栏中时,Firefox会显示图像.

I found a nice answer in this BIRT question where the base64 encoded image data is included as URI (). So I tried myself with a small static example but BIRT (4.4.2) does not show the image. Firefox displays the image when I paste the URI into the address bar.

这里有一个小的静态BIRT测试报告,可以重现该问题.

Here is a small static BIRT test report to reproduce the problem.

<?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 &lt;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>

更新:生成的HTML中的img标签看起来像

Update:The img tag in the generated HTML looks like

<img ... src="/viewer/data:image/png;base64,......"></img>

所以问题似乎是BIRT将/viewer/添加到URI.是否进行了任何配置,以便BIRT不会向报告中定义的URI添加任何内容?

So the problem seems to be that BIRT adds /viewer/ to the URI.Is there any configuration so that BIRT does not add anything to the URI defined in the report?

推荐答案

使用数据URI是一种解决方法.您可以简单地将嵌入式BASE64编码的数据用于静态图像:

Using data URI was a workaround there. You can simply use embedded BASE64 encoded data for static images:

<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编码的变量:

Or the following javascript expression to decode a BASE64 encoded variable on rendering:

<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>

这篇关于BIRT不显示base64编码的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 08:19