본문 바로가기

Centos 8/TCPPDF

[centos 8] TCPDF 사용-php에서 pdf 파일 생성하기

01. TCPDF 파일을 다운로드 받는다.

https://github.com/tecnickcom/tcpdf

 

tecnickcom/TCPDF

Official clone of PHP library to generate PDF documents and barcodes - tecnickcom/TCPDF

github.com

압축을 해제 한 후 서버에 업로드

02. 샘플 코드를 실행해본다. 저장폴더를 지정하고 해당 폴더를 쓰기권한을 줘야 한다.

<?php

	require_once "TCPDF/tcpdf_import.php";

	$html = "<h1>Hello TCPDF</h1>";
	$html .= "<i>This is the first example of TCPDF library.</i>";
	$html .= "<p style='color:#CC0000;'>End of document</p>";


	$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, "UTF-8", false);
	$pdf -> SetCreator(PDF_CREATOR);
	$pdf -> AddPage();
	$pdf -> writeHTMLCell(0, 0, "", "", $html, 0, 1, 0, true, "", true);
	$pdf -> Output(getcwd()."/data/example_test_01.pdf", "F");

?>

pdf가 생성된 파일

해당 소스를 실행하면 위와 같은 pdf 파일이 생성된것을 확인할 수 있다.

* 주의할 점 : 저장되는 폴더의 쓰기권한(707)이 주어져야 한다.