1. PDF로 파일 확인 후 출력
ServletOutputStream os = null;
// inputStream = 파일주소
// allParams = jasper로 보낼 값들
// dataSource = JRDataSource
JasperPrint jasperPrint = JasperFillManager.fillReport(inputStream, allParams, dataSource);
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);
'개발자 > Java' 카테고리의 다른 글
| POI를 이용한 대용량 엑셀 다운로드(SXSSF 방식 + sqlSessionFactory + ResultHandler + VO 활용) (1) | 2024.10.18 |
|---|---|
| [Java] 숫자, 금액을 한글로 변환 (0) | 2024.06.26 |
| [Java] Collections.frequency() 사용법 (0) | 2024.06.13 |
| [Java] POI로 엑셀 만들기(AbstractExcel 사용) (1) | 2024.06.11 |
| [Java] URL에 jsessionid가 따라 붙을 경우 (0) | 2023.04.20 |