composer 설치가 지원되지 않는 버전에서 사용

 

1. wkhtmltopdf 다운로드 - OS에 맞게 다운로드를 한다.

 

https://wkhtmltopdf.org/downloads.html

 

wkhtmltopdf

All downloads are currently hosted via Github releases, so you can browse for a specific download or use the links below. Stable The current stable series is 0.12.5, which was released on June 11, 2018 – see changes since 0.12.4. OS Flavor Downloads Commen

wkhtmltopdf.org

 

 

 

2. .rpm 파일의 압축을 풀어준다.

- 7-Zip 을 추천

 

 

3. wkhtmltox-0.12.5-1.centos6.x86_64.cpio 압축을 풀어준다.

 

 

4. usr/local 폴더에 bin, include, lib, share 폴더가 나온다.

 

이 폴더 안의 파일들을 각 위치에 맞게 실서버에 올린다

 

 

5. 코드 작성

 

index.php

<form name="WkhtmlPdfForm" id="WkhtmlPdfForm" action="/pdf_down.php" method="post" accept-charset="UTF-8" enctype="multipart/form-data">
	파라미터들
</form>

pdf_down.php

<?

header('Content-Type: text/html; charset=UTF-8');
$url = "http://www.naver.com";
$down_name = "test";

//tmp폴더의 test.pdf 저장
exec('/usr/local/bin/wkhtmltopdf -L 10mm -R 10mm -T 10mm -B 10mm "'.$url.'" "tmp/'.$down_name.'.pdf" 2>&1');

//tmp폴더의 test.pdf를 클라이언트가 다운받을 수 있도록
$sFilePath = 'tmp/'.$down_name.'.pdf';
$sFileName = $down_name.'.pdf';

header("Content-Disposition: attachment; filename=\"".$sFileName."\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".strval(filesize($sFilePath)));
header("Cache-Control: cache, must-revalidate");
header("Pragma: no-cache");
header("Expires: 0");

echo file_get_contents($sFilePath);
flush();
unlink($sFilePath);//tmp폴더의 test.pdf 파일을 삭제

?>

 

 

6. wkhtmltopdf font 적용 안될 때

usr/share/fonts/원하는 폰트.ttf 을 업로드한다.(폰트 설치)

 

 

 


WRITTEN BY
beautifulhill

,