출처: https://bumcrush.tistory.com/182 [맑음때때로 겨울]
반응형

build.gradle 파일 의존성 추가

	implementation 'net.sf.jasperreports:jasperreports:6.9.0'
	implementation 'com.lowagie:itext:2.1.7'

jasperreports 만 갖고오게 되면 오류가 발생한다.

itext 도 반드시 같이 갖고 와야 오류가 발생하지 않는다. 

jasperReports 는 itext 를 통하여 파일을 제어 하기 때문에 반드시 의존성추가를 해줘야한다.

itext 추가안해서 하루죙일 해맴 ㅠ

 

List<PersonDTO> rsDto = new ArrayList<>();
rsDto.add(dto);
rsDto.add(dto);
rsDto.add(dto);
JRBeanCollectionDataSource beanCollectionDataSource = new JRBeanCollectionDataSource(rsDto);
JasperReport compileReport = JasperCompileManager.compileReport(new FileInputStream("src/main/resources/invoice.jrxml"));
HashMap<String, Object> map = new HashMap<>();
JasperPrint report = JasperFillManager.fillReport(compileReport, map, beanCollectionDataSource);
JasperExportManager.exportReportToPdfFile(report, "invoice.pdf");

자바 코드로 나는 Service 단에 구현 해놨다. 

PersonDTO 에는 add_dt, kor_nm, manager_comments, reserve_gbn, user_comments 등이 getter setter 로 구성되어있다.

 

"src/main/resources/" resource 경로에다가 invoice.jrxml 템플릿을 생성해줘야 이 파일을 읽어서 템플릿에다가 데이터를 때려박아준다.. 

 

 

실행시키면 프로젝트 폴더 밑에 "invoice.pdf" 파일이 하나 떨어질것이다.

 

하지만 추가적으로 문제가 있다.

 

한글이 안나옴!!

 

폰트 설정해줘야 하는데 다음글에서 설명하겠습니다.

 

반응형

+ Recent posts