如何在jasper报告中显示图像 [英] how to display image in jasper reports

查看:750
本文介绍了如何在jasper报告中显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个碧玉报告。但是现在我需要在碧玉报告中放置徽标,
我将报告和徽标放在同一个文件夹中,但我无法运行报告,它说

I created a jasper report .but now I need to place logo in that jasper reports, I placed report and logo in same folder , but i am not able to run the report , its say

   net.sf.jasperreports.engine.JRException: Byte data not found at : kh_logo.jpg

如果我给出完整路径然后jar文件创建问题,那么在jar文件报告中无法找到该徽标图像,我正在使用网络豆帮助

if i am giving full path then jar file creates problem , then in jar file report is not able to find that logo image , i am using net beans please help

 I am using netbeans and i am placing report and logo in the src folder , but when I 
click on print report it is not able to find that logo


推荐答案

那里我找到了两个可能的解决方案:

There are two possible solutions I've found to this problem:

解决方案1:使用相对路径。

使用绝对路径可能在您的服务器环境中不起作用。因此,使用相对路径会更好。最好将'kh_logo.png'文件放在与.jrmxl或.jasper文件相同的文件夹中,并使用以下内容引用它:

Using an absolute path may not work in your server environment. Hence it will be better to use a relative path. It would be good to place the 'kh_logo.png' file in the same folder as the .jrmxl or .jasper file and reference it using something like this:

<image>
            <reportElement uuid="generated_uuid" x="8" y="9" width="170" height="51"/>
            <imageExpression><![CDATA["kh_logo.png"]]></imageExpression>
</image>

如果不起作用.....

If that doesn't work.....

解决方案2:使用文件解析器

此解决方案仅用于Java代码。在这里,您将自己的文件解析器作为参数传递给报表。喜欢这样..

This solution is only to be used in Java code. Here you pass your own file resolver to the report as a parameter. Like so..

 ///Jasper Resolver
       FileResolver fileResolver = new FileResolver() {

        @Override
        public File resolveFile(String fileName) {
           URI uri;
           try {
             uri = new URI(this.getClass().getResource(fileName).getPath());
             return new File(uri.getPath());
           } catch (URISyntaxException e) {
             e.printStackTrace();
             return null;
           }
       }
   };
       parameters.put("REPORT_FILE_RESOLVER", fileResolver);

然后你就像上面那样引用它。

Then you reference it as you'd do above.

希望这有助于某人。

这篇关于如何在jasper报告中显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆