1. PDF로 파일 확인 후 출력

    ServletOutputStream os = null;
    // inputStream = 파일주소
    // allParams = jasper로 보낼 값들
    // dataSource = JRDataSource
    JasperPrint jasperPrint = JasperFillManager.fillReport(inputStream, allParams, dataSource);
           
    JRPdfExporter exporter = new JRPdfExporter(DefaultJasperReportsContext.getInstance());
    exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
               
    os = response.getOutputStream();
    exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(os));
    response.setContentType("application/pdf");
               
    String fileName = URLEncoder.encode("리포트_테스트", "UTF-8").replace("+", "%20");
    response.setHeader("Content-Disposition", "inline; filename=\"" + fileName + ".pdf\"");
               
    SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
               
    configuration.setPdfVersion(PdfVersionEnum.VERSION_1_7);
    configuration.setMetadataTitle("리포트_테스트");
    exporter.setConfiguration(configuration);
               
    // PDF 출력
    exporter.exportReport();

 

2. PDF로 파일 확인 없이 바로 출력

    //  inputStream = 파일주소
    //  allParams = jasper로 보낼 값들
    //  dataSource = JRDataSource
    JasperPrint jasperPrint = JasperFillManager.fillReport(inputStream, allParams, dataSource);
    
    // OrientationEnum.PORTRAIT = 세로 방향
    // OrientationEnum.LANDSCAPE = 가로 방향
    jasperPrint.setOrientation(OrientationEnum.PORTRAIT);

    // 바로 프린트
    JasperPrintManager.printReport(jasperPrint, false);