반응형
TCPDF 설치 명령어
cd /usr/share/php/
wget https://jaist.dl.sourceforge.net/project/tcpdf/tcpdf_6_3_2.zip --no-check-certificate
unzip tcpdf_6_3_2.zip
나눔 폰트 설치 명령어
cd /usr/share/fonts/
wget http://cdn.naver.com/naver/NanumFont/fontfiles/NanumFont_TTF_ALL.zip
unzip NanumFont_TTF_ALL.zip -d NanumFont
cd /usr/share/php/tcpdf/tools/
ls /usr/share/fonts/NanumFont/*
ls /usr/share/fonts/NanumFont/* | xargs -I TTF php tcpdf_addfont.php -i TTF
ll /usr/share/php/tcpdf/fonts/ | grep nanum
PDF 변환 예제 코드
<?php
require_once('/usr/share/php/tcpdf/examples/tcpdf_include.php');
$html = <<<EOD
<h3>Hello World</h3>
<i>PDF Generated by TCPDF</i>
EOD;
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
//$pdf->SetFont('nanumgothic', '', 14, '', true);
$pdf->SetFont('nanumgothic');
$pdf->SetDefaultMonospacedFont("nanumgothic_coding");
$pdf->AddPage();
$pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
//$pdf->Output(getcwd().'/001.pdf', 'F'); // 실제 파일 생성됨
$pdf->Output('001.pdf', 'I'); // 화면으로 보여줌
?>
예제 코드 실행 화면
출처
'Study > WEB' 카테고리의 다른 글
[Spring Boot With Kotlin] Web Server Tutorial (Feat. Intellij) (0) | 2022.07.23 |
---|---|
JSP(Java Server page)와 Java Servlet (0) | 2022.07.13 |
Wordpress REST API Activation (0) | 2022.05.17 |
[Kotlin] lazy (0) | 2022.01.06 |
[Kotlin] Data Class (0) | 2022.01.06 |
댓글