【问题标题】:how to display image in jasper reports如何在碧玉报告中显示图像
【发布时间】:2014-02-16 20:31:02
【问题描述】:

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

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

如果我给出完整路径,则 jar 文件会产生问题,然后在 jar 文件中报告无法找到该徽标图像,我正在使用 net beans,请帮助

 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

【问题讨论】:

  • 你能发布包含(和包围)图像项的 jrxml 吗?

标签: java jasper-reports


【解决方案1】:

您的图像需要位于类路径上的文件夹中并以相对方式引用。

【讨论】:

    【解决方案2】:

    我发现这个问题有两种可能的解决方案:

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

    使用绝对路径可能不适用于您的服务器环境。因此,最好使用相对路径。最好将“kh_logo.png”文件放在与 .jrmxl 或 .jasper 文件相同的文件夹中,并使用以下方式引用它:

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

    如果这不起作用.....

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

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

     ///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);
    

    然后像上面那样引用它。

    希望这对某人有所帮助。

    【讨论】:

      猜你喜欢
      • 2011-02-14
      • 1970-01-01
      • 1970-01-01
      • 2017-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多