diff --git a/app/Services/HR/PayrollService.php b/app/Services/HR/PayrollService.php index 6438c8d7..a92f9878 100644 --- a/app/Services/HR/PayrollService.php +++ b/app/Services/HR/PayrollService.php @@ -876,7 +876,8 @@ public function sendPayslip(int $id): ?array 'net_salary' => (int) $payroll->net_salary, ]; - // PDF 생성 + // PDF 생성 (한글 폰트 자동 등록) + $this->ensureKoreanFont(); $month = str_pad($payslipData['pay_month'], 2, '0', STR_PAD_LEFT); $pdf = Pdf::loadView('emails.payslip', ['payslipData' => $payslipData]) ->setPaper('a4'); @@ -897,6 +898,57 @@ public function sendPayslip(int $id): ?array ]; } + /** + * DomPDF에 한글(NanumGothic) 폰트 등록 (최초 1회만 실행) + */ + private function ensureKoreanFont(): void + { + $fontDir = storage_path('fonts'); + $installedFile = $fontDir.'/installed-fonts.json'; + + // 이미 등록되어 있으면 스킵 + if (file_exists($installedFile)) { + $installed = json_decode(file_get_contents($installedFile), true) ?: []; + if (isset($installed['nanumgothic'])) { + return; + } + } + + // 시스템에 설치된 NanumGothic 찾기 + $fontPaths = [ + 'normal' => '/usr/share/fonts/truetype/nanum/NanumGothic.ttf', + 'bold' => '/usr/share/fonts/truetype/nanum/NanumGothicBold.ttf', + ]; + + if (! file_exists($fontPaths['normal'])) { + return; + } + + if (! is_dir($fontDir)) { + mkdir($fontDir, 0755, true); + } + + // storage/fonts/에 복사 후 DomPDF에 등록 + foreach ($fontPaths as $weight => $src) { + $dst = $fontDir.'/'.basename($src); + if (! file_exists($dst)) { + copy($src, $dst); + } + } + + $dompdf = app(\Barryvdh\DomPDF\PDF::class)->getDomPDF(); + $fm = $dompdf->getFontMetrics(); + $fm->registerFont( + ['family' => 'nanumgothic', 'style' => 'normal', 'weight' => 'normal'], + $fontDir.'/NanumGothic.ttf' + ); + $fm->registerFont( + ['family' => 'nanumgothic', 'style' => 'normal', 'weight' => 'bold'], + $fontDir.'/NanumGothicBold.ttf' + ); + $fm->saveFontFamilies(); + } + /** * 급여 설정 수정 */ diff --git a/resources/views/emails/payslip.blade.php b/resources/views/emails/payslip.blade.php index 93779c8b..96175ddf 100644 --- a/resources/views/emails/payslip.blade.php +++ b/resources/views/emails/payslip.blade.php @@ -3,7 +3,7 @@