본문 바로가기

정보공유/정보공유

mPDF 한글 폰트 추가

소통을 디자인하는 아이티 카이로스입니다^^


mPDF에 한글 폰트를 추가하고 강제로 pdf 출력에 적용하는 방법입니다~ 

클리앙 댓글로 도와주신 2분께 감사 인사드립니다^^


사용된 버전 : mPDF 6.1.0 26/04/2016 (제 생일이군요!)

config.php

config_fonts.php

config_fonts-distr-without-OTL.php

GyeonggiTitle_Light.ttf

GyeonggiTitle_Medium.ttf

NanumBarunGothic.ttf

NanumBarunGothicBold.ttf



1. config.php 파일에 useAdobeCJK가 true 이면 한글 출력이 문제없습니다만 HYSMyeongJo라는 예쁘지 않고 가독성이 떨어지는 폰트로 파일이 생성됩니다. 나눔 바른 고딕이나 경기도체 ttf 파일을 구해 적용해 보겠습니다.


1
2
3
 
this->useAdobeCJK = true;
 
cs


pdf 파일을 생성 후 속성을 보면 HYSMyeongJo로 한글 폰트가 설정됨


2. 경기도체(제목) TTF 파일을 아래 경로에 복사합니다. 필요시 권한도 부여해주세요.



3. config_fonts.php 파일과 config_fonts-distr-without-OTL.php 파일을 열어서 추가한 폰트를 정의합니다. 저는 itkairosfont라고 경기도체를 정의했습니다. 그리고 각 파일의 가장 하단에 정의한 폰트 이름을 입력합니다. 아래 코드 참고해주세요~


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
    /* CJK fonts */
    "unbatang" => array(/* Korean */
        'R' => "UnBatang_0613.ttf",
    ),
    "sun-exta" => array(
        'R' => "Sun-ExtA.ttf",
        'sip-ext' => 'sun-extb'/* SIP=Plane2 Unicode (extension B) */
    ),
    "sun-extb" => array(
        'R' => "Sun-ExtB.ttf",
    ),
    "nanumbarungothic" => array(/* Korean */
        'R' => "NanumBarunGothic.ttf",
        'B' => "NanumBarunGothicBold.ttf",
    ),
    "itkairosfont" => array(/* Korean */
        'R' => "GyeonggiTitle_Light.ttf",
        'B' => "GyeonggiTitle_Medium.ttf",
    ),
 
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$this->sans_fonts = array('itkairosfont''dejavusanscondensed''sans''sans-serif''cursive''fantasy''dejavusans''freesans''liberationsans',
    'arial''helvetica''verdana''geneva''lucida''arialnarrow''arialblack''arialunicodems',
    'franklin''franklingothicbook''tahoma''garuda''calibri''trebuchet''lucidagrande''microsoftsansserif',
    'trebuchetms''lucidasansunicode''franklingothicmedium''albertusmedium''xbriyaz''albasuper''quillscript',
    'humanist777''humanist777black''humanist777light''futura''hobo''segoeprint'
);
 
$this->serif_fonts = array('itkairosfont''dejavuserifcondensed''serif''dejavuserif''freeserif''liberationserif',
    'timesnewroman''times''centuryschoolbookl''palatinolinotype''centurygothic',
    'bookmanoldstyle''bookantiqua''cyberbit''cambria',
    'norasi''charis''palatino''constantia''georgia''albertus''xbzar''algerian''garamond',
);
 
$this->mono_fonts = array('itkairosfont''dejavusansmono''mono''monospace''freemono''liberationmono''courier''ocrb''ocr-b''lucidaconsole',
    'couriernew''monotypecorsiva'
);
 
cs


4. 기본 작업은 마쳤습니다. mpdf가 다른 솔루션과 연동돼 있다면 해당 솔루션에서 이 작업으로 추가한 폰트로 지정하시면 되시고 그것과 별개로 항상 경기도체로 출력되게 하려면 config.php 파일에 autoScriptToLang 을 False로 설정하면 됩니다.


1
2
3
4
// AUTOMATIC FONT SELECTION
// Based on script and/or language
$this->autoScriptToLang = false;    
 
cs


아름답게 적용되었습니다.. (감동)


당사는 조건 없이 오픈소스 연구 내용을 공유하고 있습니다. IT 기술로 세상이 더욱더 이롭게 변하기를 바랍니다.


DESIGN THE COMMUNICATION, ITKAIROS.