반응형
1. 최신 dompdf 다운로드
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
'Programming > PHP' 카테고리의 다른 글
라라벨 설치 및 개발서버 띄우기 (0) | 2023.01.31 |
---|---|
php + jquery(ajax) + json 기본 (0) | 2023.01.31 |
[코드이그나이터] 세션을 데이터베이스에 남기기 (0) | 2022.12.28 |
[코드이그나이터] 쿼리 찍어보기 (0) | 2022.12.09 |
[코드이그나이터] 리스트, 페이징 추가, 페이징 레이아웃 변경하기 (0) | 2022.11.15 |
댓글