ireport生成pdf黑体粗体字方法

Map parameters = new HashMap();
		parameters.put("accede", accedeBean);
		
		ServletContext servletContext = ServletActionContext
				.getServletContext();
		String sourceFileName = servletContext
				.getRealPath("/print/jasper_design/accede.jasper");
		String dir = ServletActionContext.getServletContext().getRealPath(
				"/print/gen_file/");
		File file = new File(dir);
		if (!file.isDirectory()) {
			file.mkdir();
		}
		String relatePath = "/print/gen_file/" + userId + "_" + operationId
				+ "_Accede_" + (new Date().getTime()) + ".pdf";
		String filePath = servletContext.getRealPath(relatePath);
		JasperPrint jasperPrint;
		try {
			jasperPrint = JasperFillManager.fillReport(sourceFileName,
					parameters);
			
//			 pdf黑体加粗
			Map fontsMap = new HashMap();
			fontsMap.put(new FontKey("黑体", true, false), new PdfFont(
					"STSong-Light", "UniGB-UCS2-H", true, true, false));
			
			
			JRPdfExporter jrPdfExporter = new JRPdfExporter();
			jrPdfExporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, filePath);   
			jrPdfExporter.setParameter(JRExporterParameter.FONT_MAP, fontsMap); 
			jrPdfExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);        

	        jrPdfExporter.exportReport();  
		} catch (JRException e) {
			e.printStackTrace();
		}

你可能感兴趣的:(IREPORT)