본문 바로가기

자바스토리/Spring

SPRING BOOT & JASPER

1.Jaspersoft@Studio 설치

1) 회원가입 - https://community.jaspersoft.com/ 
2) 프로그램 다운로드 및 설치
https://community.jaspersoft.com/files/file/19-jaspersoft%C2%AE-studio-community-edition/

 

Jaspersoft® Studio Community Edition

This powerful eclipse-based report designer for JasperReports and JasperReports Server can build reports from any data source and format the look and feel for print or on-screen reading giving developers the flexibility they need. It can deploy to JasperRe

community.jaspersoft.com

 

 

Home

Welcome to the Jaspersoft Community Whether you are embedding dashboards into your application or looking for pixel-perfect reporting, our community site provides the information, resources, and guidance you need to be successful with Jaspersoft. Forum Ask

community.jaspersoft.com

 

2.spring boot 설정

1)Jasper jrxml 폴더 생성 - 해당 위치에 작성한 jasper 파일을 가져다 놓는다.

resources > jasper

2)컨트롤러

@GetMapping(value="test")
    public ResponseEntity<byte[]> jasperReport(@RequestParam(value = "date") String date) throws Exception, JRException {
// 에디터 조회
        SearchRequest params = new SearchRequest();
        params.setSearchDate(searchDate);
        List<SearchResponse> result = service.selectReportList(params);

        // 받아온 데이터를 jasper datasource로 등록
        JRBeanCollectionDataSource beanCollectionDataSource = new JRBeanCollectionDataSource(result);
        
        // jasper 컴파일할 양식 설정 - 만들어둔 jrxml 파일 경로 설정
        JasperReport compileReport = JasperCompileManager.compileReport(new FileInputStream("src/main/resources/jasper/saleDay.jrxml"));
        
        // datasource를 매핑해 양식(jrxml)에 맞게 컴파일
        HashMap<String, Object> map = new HashMap<String, Object>();
        JasperPrint report = JasperFillManager.fillReport(compileReport, map, beanCollectionDataSource);
        
        // return 방식1. 컴파일된 pdf파일을 현재 폴더에 생성
        //  JasperExportManager.exportReportToPdfFile(report, "BoardStatus.pdf");
        // return "generated";
        
        // return 방식2. 프린트 및 adobe pdf 화면 띄우기
        // *주의: 프론트에서 화면을 띄울 수 없고, 서버 url을 직접 띄워야함..
        byte[] data = JasperExportManager.exportReportToPdf(report);
        return ResponseEntity.ok()
                .header("Content-Disposition", "attachment; filename=saleDay.pdf")
                .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_PDF.toString())
                .body(data);
    }

3)JSP

<form id="searchForm">
    <div class="form_inline wide">
        <span class="form_txt">조회일자</span>
        <input type="text" class="datepicker" id="searchDate" name="searchDate" placeholder="YYYY-MM-DD">
        <span class="form_label"><a class="btn btn_form btn_gray" href="javascript:REPORT_EVENT.report();"    id="searchBtn">보고서</a></span>
    </div>
</form>

4)script

var REPORT_EVENT = {
    report: function(){
        var params = $("#searchForm").serialize();
        var url = "/report/test?" + params;
        window.open(url);
    }
}

3.Jsper 한글설정

#참조 - https://calatheas.tistory.com/entry/Jasperreports-2-%ED%95%9C%EA%B8%80%ED%8F%B0%ED%8A%B8-%EC%84%A4%EC%A0%95

1) JasperStudio 설정

2)spring boot 설정

A.resource/jasperreports_extension.properties 파일 작성net.sf.jasperreports.extension.registry.factory.simple.font.families=net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory
net.sf.jasperreports.extension.simple.font.families.korean=프로젝트 안의 fonts.xml 경로

B.프로젝트 내의 경로/fonts.xml
<?xml version="1.0" encoding="UTF-8"?>
<fontFamilies>
<fontFamily name="폰트이름(jasper에서 선택한 폰트이름과 동일)">
    <normal>"프로젝트 안의 폰트경로"</normal>
    <pdfEncoding>Identity-H</pdfEncoding>
    <pdfEmbedded>true</pdfEmbedded>
</fontFamily>
</fontFamilies>

3)jvm 설정

 - C:\Program Files\Java\jdk1.8.0_202\jre\lib  JRE에 fontconfig.properties.src 최하단에 폰트 추가

- C:\Program Files\Java\jdk1.8.0_202\jre\lib\fonts 폰트 파일 생성

 

[JasperReports] #2 한글폰트 설정

pdf 로 한글을 출력하려면 한글폰트를 pdf 에 embed 해야한다. Jasper studio 에서 미리보기 할 때는 한글이 잘 나오지만(아마 os에 설치된 폰트를 가져오는 듯) pdf 로 출력해보면 한글이 출력되지 않는

calatheas.tistory.com

 

'자바스토리 > Spring' 카테고리의 다른 글

Error unmappable character for encoding MS949  (0) 2023.12.18
RequestParam examples  (0) 2017.06.01
Jackson 라이브러리  (0) 2017.03.30
log4jdbc-remix 설정  (0) 2016.03.07
logging framework logback  (0) 2016.03.07