From 70ff4ab40e8ff9a2ed2dd17711fdb0729c7ff8b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B6=8C=ED=98=81=EC=84=B1?= Date: Thu, 26 Feb 2026 15:37:24 +0900 Subject: [PATCH] =?UTF-8?q?fix:TCPDF=20=ED=8F=B0=ED=8A=B8=EB=A5=BC=20PDF?= =?UTF-8?q?=20=EC=9D=B8=EC=8A=A4=ED=84=B4=EC=8A=A4=EC=97=90=20=EC=A0=84?= =?UTF-8?q?=EC=B2=B4=20=EA=B2=BD=EB=A1=9C=EB=A1=9C=20=EB=93=B1=EB=A1=9D?= =?UTF-8?q?=ED=95=98=EC=97=AC=20font=20definition=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - addTTFfont()는 storage에 캐시만 생성하고 SetFont() 시 K_PATH_FONTS(vendor)에서 찾아 실패 - registerKoreanFont()로 분리: 캐시 생성 + $pdf->AddFont() 전체 경로 등록 - mergeSignatures(), generatePreview() 양쪽에 적용 --- app/Services/ESign/PdfSignatureService.php | 35 +++++++++++++++------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/app/Services/ESign/PdfSignatureService.php b/app/Services/ESign/PdfSignatureService.php index b170ea01..cfa14ddb 100644 --- a/app/Services/ESign/PdfSignatureService.php +++ b/app/Services/ESign/PdfSignatureService.php @@ -13,27 +13,38 @@ class PdfSignatureService private ?string $koreanFontName = null; /** - * Pretendard 한글 폰트를 등록하고 폰트 이름을 반환한다. - * PDF 문서와 동일한 폰트로 필드 텍스트를 렌더링하여 일관성을 유지한다. + * PDF 인스턴스에 Pretendard 한글 폰트를 등록한다. + * 폰트 캐시를 storage에 생성하고, PDF 인스턴스에 전체 경로로 등록하여 + * vendor 디렉토리 쓰기 권한 문제를 방지한다. */ - private function getKoreanFont(): string + private function registerKoreanFont(Fpdi $pdf): void { - if ($this->koreanFontName) { - return $this->koreanFontName; + $fontPath = storage_path('fonts/Pretendard-Regular.ttf'); + if (! file_exists($fontPath)) { + return; } - // 1순위: 프로젝트 내장 Pretendard (로컬/서버 공통) - $fontPath = storage_path('fonts/Pretendard-Regular.ttf'); + $fontCacheDir = storage_path('app/private/fonts'); + $fontDefFile = $fontCacheDir.'/pretendard.php'; - if (file_exists($fontPath)) { - // 폰트 캐시를 storage에 저장 (vendor 디렉토리 쓰기 권한 문제 방지) - $fontCacheDir = storage_path('app/private/fonts'); + // 폰트 캐시 파일이 없으면 생성 + if (! file_exists($fontDefFile)) { if (! is_dir($fontCacheDir)) { mkdir($fontCacheDir, 0775, true); } - $this->koreanFontName = \TCPDF_FONTS::addTTFfont($fontPath, 'TrueTypeUnicode', '', 96, $fontCacheDir.'/'); + \TCPDF_FONTS::addTTFfont($fontPath, 'TrueTypeUnicode', '', 96, $fontCacheDir.'/'); } + // PDF 인스턴스에 전체 경로로 폰트 등록 (K_PATH_FONTS 의존 제거) + $pdf->AddFont('pretendard', '', $fontDefFile); + $this->koreanFontName = 'pretendard'; + } + + /** + * 등록된 한글 폰트 이름을 반환한다. + */ + private function getKoreanFont(): string + { return $this->koreanFontName ?: 'helvetica'; } @@ -53,6 +64,7 @@ public function mergeSignatures(EsignContract $contract): string $pdf = new Fpdi; $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); + $this->registerKoreanFont($pdf); $pageCount = $pdf->setSourceFile($originalPath); @@ -123,6 +135,7 @@ public function generatePreview(EsignContract $contract): string $pdf = new Fpdi; $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); + $this->registerKoreanFont($pdf); $pageCount = $pdf->setSourceFile($originalPath);