BIRT动态图像报告生成
BIRT dyanamic image report generation
在我的数据库中我有 table Rapid_Slum_Appraisal
id | general_info_left_image
--------------------------------------
1 | http://127.0.0.1/media/image1.jpg
2 | http://127.0.0.1/media/image2.jpg
如果你点击 URL 你可以在浏览器中看到图像。
我已经使用 BIRT 创建了 image.rptdesign 文件 designer.In 我已经创建了一个数据源和数据集来从数据库中检索 general_info_left_image。
我遵循的步骤 -
首先我创建了数据源和数据集以从数据库中检索图像。
然后我从工具箱中拖拽图像报表项来创建动态图像。
当将数据类型设置为 Blob 并尝试使用 BIRT 查看器查看报告时,我看到以下错误并且未显示图像。
Can not convert the value of
http://127.0.0.1:8000/media/2697dd7fdfef2c54b6bbc4698ec14b8e_7rRHk5J.jpg
to Binary type
- 当我将数据类型设置为字符串时,图像不显示
image.rptdesign 文件:
<?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.6.0.v201606072122</property>
<property name="units">in</property>
<property name="iconFile">/templates/blank_report.gif</property>
<property name="bidiLayoutOrientation">ltr</property>
<property name="imageDPI">96</property>
<data-sources>
<oda-data-source extensionID="org.eclipse.birt.report.data.oda.jdbc" name="django" id="4">
<list-property name="privateDriverProperties">
<ex-property>
<name>metadataBidiFormatStr</name>
<value>ILYNN</value>
</ex-property>
<ex-property>
<name>disabledMetadataBidiFormatStr</name>
</ex-property>
<ex-property>
<name>contentBidiFormatStr</name>
<value>ILYNN</value>
</ex-property>
<ex-property>
<name>disabledContentBidiFormatStr</name>
</ex-property>
</list-property>
<property name="odaDriverClass">org.postgresql.Driver</property>
<property name="odaURL">jdbc:postgresql://127.0.0.1/django</property>
<property name="odaUser">postgres</property>
<encrypted-property name="odaPassword" encryptionID="base64">c29mdGNvcm5lcg==</encrypted-property>
</oda-data-source>
</data-sources>
<data-sets>
<oda-data-set extensionID="org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" name="image" id="5">
<property name="nullsOrdering">nulls lowest</property>
<list-property name="columnHints">
<structure>
<property name="columnName">general_info_left_image</property>
<property name="analysis">dimension</property>
<text-property name="displayName">general_info_left_image</text-property>
<text-property name="heading">general_info_left_image</text-property>
</structure>
</list-property>
<structure name="cachedMetaData">
<list-property name="resultSet">
<structure>
<property name="position">1</property>
<property name="name">general_info_left_image</property>
<property name="dataType">string</property>
</structure>
</list-property>
</structure>
<property name="dataSource">django</property>
<list-property name="resultSet">
<structure>
<property name="position">1</property>
<property name="name">general_info_left_image</property>
<property name="nativeName">general_info_left_image</property>
<property name="dataType">string</property>
</structure>
</list-property>
<xml-property name="queryText"><![CDATA[select general_info_left_image
from public.master_rapid_slum_appraisal]]></xml-property>
<xml-property name="designerValues"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<model:DesignValues xmlns:design="http://www.eclipse.org/datatools/connectivity/oda/design" xmlns:model="http://www.eclipse.org/birt/report/model/adapter/odaModel">
<Version>2.0</Version>
<design:ResultSets derivedMetaData="true">
<design:resultSetDefinitions>
<design:resultSetColumns>
<design:resultColumnDefinitions>
<design:attributes>
<design:identifier>
<design:name>general_info_left_image</design:name>
<design:position>1</design:position>
</design:identifier>
<design:nativeDataTypeCode>12</design:nativeDataTypeCode>
<design:precision>100</design:precision>
<design:scale>0</design:scale>
<design:nullability>NotNullable</design:nullability>
<design:uiHints>
<design:displayName>general_info_left_image</design:displayName>
</design:uiHints>
</design:attributes>
<design:usageHints>
<design:label>general_info_left_image</design:label>
<design:formattingHints>
<design:displaySize>100</design:displaySize>
</design:formattingHints>
</design:usageHints>
</design:resultColumnDefinitions>
</design:resultSetColumns>
<design:criteria/>
</design:resultSetDefinitions>
</design:ResultSets>
</model:DesignValues>]]></xml-property>
</oda-data-set>
</data-sets>
<page-setup>
<simple-master-page name="Simple MasterPage" id="2">
<page-footer>
<text id="3">
<property name="contentType">html</property>
<text-property name="content"><![CDATA[<value-of>new Date()</value-of>]]></text-property>
</text>
</page-footer>
</simple-master-page>
</page-setup>
<body>
<table id="6">
<property name="dataSet">image</property>
<list-property name="boundDataColumns">
<structure>
<property name="name">general_info_left_image</property>
<text-property name="displayName">general_info_left_image</text-property>
<expression name="expression" type="javascript">dataSetRow["general_info_left_image"]</expression>
<property name="dataType">string</property>
</structure>
</list-property>
<column id="15"/>
<header>
<row id="7">
<cell id="8"/>
</row>
</header>
<detail>
<row id="10">
<cell id="11">
<image id="16">
<property name="dataSet">image</property>
<list-property name="boundDataColumns">
<structure>
<property name="name">general_info_left_image</property>
<expression name="expression" type="javascript">dataSetRow["general_info_left_image"]</expression>
<property name="dataType">blob</property>
<property name="allowExport">true</property>
</structure>
</list-property>
<property name="source">expr</property>
<expression name="valueExpr">row["general_info_left_image"]</expression>
</image>
</cell>
</row>
</detail>
<footer>
<row id="13">
<cell id="14"/>
</row>
</footer>
</table>
</body>
</report>
系统信息:
Ubuntu 16.04
BIRT 4.6.0
Java Version
openjdk version "1.8.0_91"
OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-3ubuntu1~16.04.1-b14)
OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)
现在我明白了混乱的根源。从数据库中检索的不是实际图像,而是它的位置。
为此,您必须确保查看报告的每个人都可以访问 link。 (也就是说,您只需将 link 粘贴到浏览器中,您就会看到图像)
修复报告的步骤:
- 从图像中删除数据集。您希望它通过它所在的 table 获取数据,因此将其设置为 None.
- table 将 general_info_left_image 设置为字符串,就像在数据集中一样,所以这是正确的。无需更改。
- Select 图像并将 'Select from image' 设置为 URI
- 输入 URI,select javascript 语法,然后输入表达式生成器。
- Select可用列绑定,selecttable,selectgeneral_info_left_image(双击将其添加到表达式中)。您的表达式应为:row["general_info_left_image"]
这应该有效。祝你好运。
在我的数据库中我有 table Rapid_Slum_Appraisal
id | general_info_left_image
--------------------------------------
1 | http://127.0.0.1/media/image1.jpg
2 | http://127.0.0.1/media/image2.jpg
如果你点击 URL 你可以在浏览器中看到图像。
我已经使用 BIRT 创建了 image.rptdesign 文件 designer.In 我已经创建了一个数据源和数据集来从数据库中检索 general_info_left_image。
我遵循的步骤 -
首先我创建了数据源和数据集以从数据库中检索图像。
然后我从工具箱中拖拽图像报表项来创建动态图像。
当将数据类型设置为 Blob 并尝试使用 BIRT 查看器查看报告时,我看到以下错误并且未显示图像。
Can not convert the value of http://127.0.0.1:8000/media/2697dd7fdfef2c54b6bbc4698ec14b8e_7rRHk5J.jpg to Binary type
- 当我将数据类型设置为字符串时,图像不显示
image.rptdesign 文件:
<?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.6.0.v201606072122</property>
<property name="units">in</property>
<property name="iconFile">/templates/blank_report.gif</property>
<property name="bidiLayoutOrientation">ltr</property>
<property name="imageDPI">96</property>
<data-sources>
<oda-data-source extensionID="org.eclipse.birt.report.data.oda.jdbc" name="django" id="4">
<list-property name="privateDriverProperties">
<ex-property>
<name>metadataBidiFormatStr</name>
<value>ILYNN</value>
</ex-property>
<ex-property>
<name>disabledMetadataBidiFormatStr</name>
</ex-property>
<ex-property>
<name>contentBidiFormatStr</name>
<value>ILYNN</value>
</ex-property>
<ex-property>
<name>disabledContentBidiFormatStr</name>
</ex-property>
</list-property>
<property name="odaDriverClass">org.postgresql.Driver</property>
<property name="odaURL">jdbc:postgresql://127.0.0.1/django</property>
<property name="odaUser">postgres</property>
<encrypted-property name="odaPassword" encryptionID="base64">c29mdGNvcm5lcg==</encrypted-property>
</oda-data-source>
</data-sources>
<data-sets>
<oda-data-set extensionID="org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" name="image" id="5">
<property name="nullsOrdering">nulls lowest</property>
<list-property name="columnHints">
<structure>
<property name="columnName">general_info_left_image</property>
<property name="analysis">dimension</property>
<text-property name="displayName">general_info_left_image</text-property>
<text-property name="heading">general_info_left_image</text-property>
</structure>
</list-property>
<structure name="cachedMetaData">
<list-property name="resultSet">
<structure>
<property name="position">1</property>
<property name="name">general_info_left_image</property>
<property name="dataType">string</property>
</structure>
</list-property>
</structure>
<property name="dataSource">django</property>
<list-property name="resultSet">
<structure>
<property name="position">1</property>
<property name="name">general_info_left_image</property>
<property name="nativeName">general_info_left_image</property>
<property name="dataType">string</property>
</structure>
</list-property>
<xml-property name="queryText"><![CDATA[select general_info_left_image
from public.master_rapid_slum_appraisal]]></xml-property>
<xml-property name="designerValues"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<model:DesignValues xmlns:design="http://www.eclipse.org/datatools/connectivity/oda/design" xmlns:model="http://www.eclipse.org/birt/report/model/adapter/odaModel">
<Version>2.0</Version>
<design:ResultSets derivedMetaData="true">
<design:resultSetDefinitions>
<design:resultSetColumns>
<design:resultColumnDefinitions>
<design:attributes>
<design:identifier>
<design:name>general_info_left_image</design:name>
<design:position>1</design:position>
</design:identifier>
<design:nativeDataTypeCode>12</design:nativeDataTypeCode>
<design:precision>100</design:precision>
<design:scale>0</design:scale>
<design:nullability>NotNullable</design:nullability>
<design:uiHints>
<design:displayName>general_info_left_image</design:displayName>
</design:uiHints>
</design:attributes>
<design:usageHints>
<design:label>general_info_left_image</design:label>
<design:formattingHints>
<design:displaySize>100</design:displaySize>
</design:formattingHints>
</design:usageHints>
</design:resultColumnDefinitions>
</design:resultSetColumns>
<design:criteria/>
</design:resultSetDefinitions>
</design:ResultSets>
</model:DesignValues>]]></xml-property>
</oda-data-set>
</data-sets>
<page-setup>
<simple-master-page name="Simple MasterPage" id="2">
<page-footer>
<text id="3">
<property name="contentType">html</property>
<text-property name="content"><![CDATA[<value-of>new Date()</value-of>]]></text-property>
</text>
</page-footer>
</simple-master-page>
</page-setup>
<body>
<table id="6">
<property name="dataSet">image</property>
<list-property name="boundDataColumns">
<structure>
<property name="name">general_info_left_image</property>
<text-property name="displayName">general_info_left_image</text-property>
<expression name="expression" type="javascript">dataSetRow["general_info_left_image"]</expression>
<property name="dataType">string</property>
</structure>
</list-property>
<column id="15"/>
<header>
<row id="7">
<cell id="8"/>
</row>
</header>
<detail>
<row id="10">
<cell id="11">
<image id="16">
<property name="dataSet">image</property>
<list-property name="boundDataColumns">
<structure>
<property name="name">general_info_left_image</property>
<expression name="expression" type="javascript">dataSetRow["general_info_left_image"]</expression>
<property name="dataType">blob</property>
<property name="allowExport">true</property>
</structure>
</list-property>
<property name="source">expr</property>
<expression name="valueExpr">row["general_info_left_image"]</expression>
</image>
</cell>
</row>
</detail>
<footer>
<row id="13">
<cell id="14"/>
</row>
</footer>
</table>
</body>
</report>
系统信息:
Ubuntu 16.04
BIRT 4.6.0
Java Version
openjdk version "1.8.0_91"
OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-3ubuntu1~16.04.1-b14)
OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)
现在我明白了混乱的根源。从数据库中检索的不是实际图像,而是它的位置。
为此,您必须确保查看报告的每个人都可以访问 link。 (也就是说,您只需将 link 粘贴到浏览器中,您就会看到图像)
修复报告的步骤:
- 从图像中删除数据集。您希望它通过它所在的 table 获取数据,因此将其设置为 None.
- table 将 general_info_left_image 设置为字符串,就像在数据集中一样,所以这是正确的。无需更改。
- Select 图像并将 'Select from image' 设置为 URI
- 输入 URI,select javascript 语法,然后输入表达式生成器。
- Select可用列绑定,selecttable,selectgeneral_info_left_image(双击将其添加到表达式中)。您的表达式应为:row["general_info_left_image"]
这应该有效。祝你好运。