728x90

HTML 을 PDF로 출력하기 위해 테스트하고 간략하게 적어둔다.


###### TCPDF 설치 ############
# 1. 웹 브라우저에서 https://sourceforge.net/projects/tcpdf/files/ 에 접속하여 TCPDF를 다운받는다.
# 현재 기준 tcpdf_6_3_2.zip 가 가장 최신이다.
# 다운로드 받은 파일을 리눅스 /usr/share/php 경로에 업로드 한다.

# 다른 경로에 설치해도 되는데 나눔폰트 설치 경로를 변경하기 싫어서 이곳 저곳 설치해보고 그냥 이 폴더로 정했다.
cd /usr/share/php
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

# 예제파일을 참조하여 실행할 php 디렉토리에서 내용을 구현한다.

먼저 화면상으로 원하는 형태로 출력이 되는지 확인하고 최종적으로 PDF 파일로 생성되도록 하면 된다.


tcpdf_include.php 파일에서 경로를 수정해준다.

$tcpdf_include_dirs = array(
    realpath('/usr/share/php/tcpdf/tcpdf.php'),
    '/usr/share/php/tcpdf/tcpdf.php'
);

<?php
// Include the main TCPDF library (search for installation path).
require_once('tcpdf_include.php');

// Set some content to print
$html = <<<EOD
<h3>반갑습니다. PDF센터에 오신 걸 환영합니다.</h3>
<i>This is the first example of TCPDF library.</i>
EOD;

// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);

// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

// Set font
//$pdf->SetFont('nanumgothic', '', 14, '', true);
$pdf->SetFont('nanumgothic');
$pdf->SetDefaultMonospacedFont("nanumgothic_coding");

// Add a page
$pdf->AddPage();

// Print text using writeHTMLCell()
$pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);

// Close and output PDF document
//$pdf->Output(getcwd().'/001.pdf', 'F'); // 실제 파일 생성됨
$pdf->Output('001.pdf', 'I'); // 화면으로 보여줌
?>
 



참조 사이트

https://wickedmagic.tistory.com/571

https://zetawiki.com/wiki/TCPDF_%ED%95%9C%EA%B8%80_%ED%8F%B0%ED%8A%B8_%EC%82%AC%EC%9A%A9

'안드로이드 > Android QRCode' 카테고리의 다른 글

Android QRCode 샘플  (0) 2020.08.25
PHP QR code 생성하는 방법  (0) 2020.03.04
QRCode 개요  (0) 2020.03.03
블로그 이미지

Link2Me

,