JasperSoft studio入门(一)-打印机打印jasper文件java代码
打印机打印jasper文件核心代码
去博客设置页面,选择一款你喜欢的代码片高亮样式,下面展示同样高亮的 代码片
.
public static void print(Map<String, Object> parameters, String serviceName, String classpath){
try{
// 读取模板文件
ClassPathResource classPathResource = new ClassPathResource(classpath);
InputStream inputStream = classPathResource.getInputStream();
JasperPrint jasperPrint = JasperFillManager.fillReport(inputStream, parameters, new JREmptyDataSource());
PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
printRequestAttributeSet.add(MediaSizeName.ISO_A4);
PrintServiceAttributeSet printServiceAttributeSet = new HashPrintServiceAttributeSet();
// 驱动名称
printServiceAttributeSet.add(new PrinterName(serviceName, null));
JRPrintServiceExporter exporter = new JRPrintServiceExporter();
SimplePrintServiceExporterConfiguration configuration = new SimplePrintServiceExporterConfiguration();
configuration.setPrintRequestAttributeSet(printRequestAttributeSet);
configuration.setPrintServiceAttributeSet(printServiceAttributeSet);
configuration.setDisplayPageDialog(false);
configuration.setDisplayPrintDialog(false);
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
exporter.setConfiguration(configuration);
exporter.exportReport();
}catch (Exception e){
e.printStackTrace();
}
}