fix: [hr] 급여명세서 PDF 한글 폰트 깨짐 수정
- NanumGothic 폰트 자동 등록 로직 추가 (ensureKoreanFont) - storage/fonts/에 폰트 복사 후 DomPDF에 등록 (최초 1회) - payslip.blade.php font-family를 NanumGothic으로 변경 - 서버 배포 시 수동 폰트 등록 불필요
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 급여 설정 수정
|
||||
*/
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<style>
|
||||
body { font-family: 'Malgun Gothic', 'Apple SD Gothic Neo', sans-serif; margin: 0; padding: 20px; background: #fff; }
|
||||
body { font-family: 'NanumGothic', 'Malgun Gothic', sans-serif; margin: 0; padding: 20px; background: #fff; }
|
||||
.container { max-width: 720px; margin: 0 auto; background: #fff; padding: 40px 36px; }
|
||||
h1 { text-align: center; font-size: 22px; font-weight: 800; letter-spacing: 2px; margin: 0 0 28px; border-bottom: 3px solid #333; padding-bottom: 16px; }
|
||||
.info-table { width: 100%; border-collapse: collapse; margin-bottom: 20px; table-layout: fixed; }
|
||||
|
||||
Reference in New Issue
Block a user