如何在jasper报告中显示图像
我创建了一个碧玉报告。但是现在我需要在碧玉报告中放置徽标,我将报告和徽标放在同一个文件夹中,但我无法运行报告,它说
net.sf.jasperreports.engine.JRException: Byte data not found at : kh_logo.jpg
如果我给出完整路径然后jar文件创建问题,然后在jar文件报告中无法找到该徽标图像,我使用网豆请帮助
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
您的图像需要位于类路径中的文件夹中,并以相对方式引用。
我发现这个问题有两种可能的解决方案:
解决方案1:使用相对路径。
使用绝对路径可能无法在您的服务器环境中工作。 因此,使用相对路径会更好。 最好将’kh_logo.png’文件放在与.jrmxl或.jasper文件相同的文件夹中,并使用以下内容引用它:
如果这不起作用…..
解决方案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);
然后你就像上面那样引用它。
希望这有助于某人。