JasperReport6.x +Spring Boot 导出PDF汉字不显示,提示:Unpatched iText found, cannot use glyph rendering

SpringBoot + JasperReport6.x 集成报表控件,导出PDF汉字无法显示,控制台提示如下错误信息:

 WARN  net.sf.jasperreports.engine.export.PdfGlyphRenderer - Unpatched iText found, cannot use glyph rendering

SpringBoot 集成JasperReport6.x 之相关依赖:


		
		
			org.springframework.boot
			spring-boot-starter-web
		
		
		
			net.sf.jasperreports
			jasperreports
			6.10.0
		
		
			com.lowagie
			itext
			2.1.7.js4
		
		
			org.codehaus.groovy
			groovy-all
		
		
			org.mozilla
			javascript
			1.7.2
		
		
		
			org.springframework
			spring-context-support
		
		
		
			org.projectlombok
			lombok
		
	

指定JasperReport6.x 报表字体:

JasperReport6.x +Spring Boot 导出PDF汉字不显示,提示:Unpatched iText found, cannot use glyph rendering_第1张图片

jasperreports_extension.properties文件内容如下:

net.sf.jasperreports.extension.registry.factory.simple.font.families=net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory
net.sf.jasperreports.extension.simple.font.families.lobstertwo=fonts/fonts.xml

 fonts.xml配置内容如下:



    
        fonts/STSONG.TTF
        fonts/STSONG.TTF
        fonts/STSONG.TTF
        fonts/STSONG.TTF
        Identity-H
        true
        
            STS, Arial, Helvetica, sans-serif
            STS, Arial, Helvetica, sans-serif
        
    

Jaspersoft@Studio 设置相关报表字体:

JasperReport6.x +Spring Boot 导出PDF汉字不显示,提示:Unpatched iText found, cannot use glyph rendering_第2张图片

JasperReport6.x +Spring Boot 导出PDF汉字不显示,提示:Unpatched iText found, cannot use glyph rendering_第3张图片

造成控制台输出相关提示信息:

WARN  net.sf.jasperreports.engine.export.PdfGlyphRenderer - Unpatched iText found, cannot use glyph rendering

原因如下:

JasperReport6.x +Spring Boot 导出PDF汉字不显示,提示:Unpatched iText found, cannot use glyph rendering_第4张图片

在https://mvnrepository.com/ 中没有找到itext2.1.17.js7 版本下载,使用https://search.maven.org/ 检索到itext2.1.17 版本作为依赖下载本地,执行代码时出现上述错误信息。最后在jasperreport 开源的maven 仓库找到itext2.1.17.js4: http://jasperreports.sourceforge.net/maven2/com/lowagie/itext/2.1.7.js4/

核心功能代码:

@RequestMapping("/one")
	public void getReportByParam(HttpServletResponse response) {
		ServletOutputStream sosRef = null;
		// bean 连接获取
		try {
			Map map = new HashMap();				
				map.put("quarter", "第一季度");
				map.put("personUseCount", "111");
				map.put("archCount", "99");
				map.put("personCount", "74");
				map.put("textNumbs", "59/38");
				map.put("copyDrawingCount", "99");
 
			// 获取文件流
			ClassPathResource resource = new ClassPathResource("jasper" + File.separator + "Blank_A4_1.jasper");
			InputStream jasperStream = resource.getInputStream();
 
			sosRef = response.getOutputStream();
			// 重点代码
			JasperRunManager.runReportToPdfStream(jasperStream, sosRef, map, new JREmptyDataSource());
			JasperRunManager.runReportToPdfStream(jasperStream, sosRef, map);
			response.setContentType("application/pdf");
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				sosRef.flush();
				sosRef.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

依赖itext2.1.17.js 代码下载:

报表下载文件下载地质:

你可能感兴趣的:(jasperreport)