본문 바로가기
Programming/PHP

php8.0.2 + ciboard + dompdf + 한글폰트적용

by Berasix 2023. 1. 21.
반응형

2. third_party에 폴더 위치

 

3. libraries 에 클래스 생성

require_once APPPATH.'/third_party/Dompdf/autoload.inc.php';

use Dompdf\Dompdf;

class Pdf
{
    function __construct()
    {
        $pdf = new Dompdf();
        $CI = & get_instance();
        $CI->dompdf = $pdf;
    }
}

 

4. controller 에 클래스 생성

class Pdfcontroller extends CB_Controller {

    function __construct()
    {
        parent::__construct();
        $this->load->library('Pdf');
    }

    public function index()
    {
        $html = "<html>
			<head>
				<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
				<style>
					body { font-family:'nanumgothic'; }
				</style>
			</head>
			<boday><h1>english....그리고 한글</h1></body></html>";
        $this->dompdf->load_html($html);

        $this->dompdf->set_paper("A4", "portrait");
        $this->dompdf->render();
        $filename = time()."pdffile.pdf";
        
        $contents = $this->dompdf->output();
        $file_url = $_SERVER["DOCUMENT_ROOT"]."/uploadfolder/".$filename;
        $this->save_pdf($file_url, $contents);

        $pdf_url = "http://".$_SERVER["HTTP_HOST"]."/uploadfolder/".$filename; 
   }

    // 서버에 파일 저장
    public function save_pdf($file_url, $contents) {
          $pf = fopen($file_url, "w");
          fwrite($pf, $contents);
          fclose($pf);
     }
}

 

5. 한글 설정을 위해 dompdf-0.6.2, NanumGothic.ttf 이용(다운로드필요)

6. 아래 명령실행...윈도우라서 아래와 같음

php load_font.php 'NanumGothic' NanumGothic.ttf NanumGothic.ttf

** 오류가 나면, 그부분 과감히 삭제. (autoload.inc.php 에서 오류 났음)

7. 위 명령으로 생성된 아래 파일을 작업 중이던 동일 디렉터리에 넣는다.

/dompdf/lib/fonts/NanumGothic.ufm

8. third_party/Dompdf/lib/fonts/dompdf_font_family_cache.dist.php 파일 맨 아래에 다음 추가

    'nanumgothic' =>
        [
            'bold' => $distFontDir . '/NanumGothic',
            'bold_italic' => $distFontDir . '/NanumGothic',
            'italic' => $distFontDir . '/NanumGothic',
            'normal' => $distFontDir . '/NanumGothic'
        ]

별일 없다면 잘 될 것이다.

리눅스도 별반 차이 없다.

728x90

댓글