feat:PDF 서명 오버레이 합성 기능 구현

- PdfSignatureService 신규 생성 (FPDI+TCPDF 기반 PDF 합성)
- submitSignature에서 모든 서명 완료 시 자동 PDF 합성 호출
- downloadDocument에서 서명 완료 PDF 우선 제공
- setasign/fpdi, tecnickcom/tcpdf 패키지 추가

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
김보곤
2026-02-12 19:42:08 +09:00
parent a2f31d0103
commit fd5d052cb7
4 changed files with 365 additions and 5 deletions

View File

@@ -10,6 +10,7 @@
use Illuminate\Http\Request;
use App\Mail\EsignRequestMail;
use Illuminate\Support\Facades\Mail;
use App\Services\ESign\PdfSignatureService;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Illuminate\View\View;
@@ -243,6 +244,17 @@ public function submitSignature(Request $request, string $token): JsonResponse
'status' => 'completed',
'completed_at' => now(),
]);
// PDF에 서명 이미지/텍스트 합성
try {
$pdfService = new PdfSignatureService();
$pdfService->mergeSignatures($contract);
} catch (\Throwable $e) {
\Illuminate\Support\Facades\Log::error('PDF 서명 합성 실패', [
'contract_id' => $contract->id,
'error' => $e->getMessage(),
]);
}
} else {
$contract->update(['status' => 'partially_signed']);
@@ -322,13 +334,18 @@ public function downloadDocument(string $token): StreamedResponse|JsonResponse
return response()->json(['success' => false, 'message' => '문서를 찾을 수 없습니다.'], 404);
}
if (! Storage::disk('local')->exists($contract->original_file_path)) {
// 서명 완료된 PDF가 있으면 우선 제공
$filePath = $contract->signed_file_path && Storage::disk('local')->exists($contract->signed_file_path)
? $contract->signed_file_path
: $contract->original_file_path;
if (! Storage::disk('local')->exists($filePath)) {
return response()->json(['success' => false, 'message' => '문서 파일이 존재하지 않습니다.'], 404);
}
$fileName = $contract->original_file_name ?: ($contract->title . '.pdf');
return Storage::disk('local')->download($contract->original_file_path, $fileName, [
return Storage::disk('local')->download($filePath, $fileName, [
'Content-Type' => 'application/pdf',
]);
}