From 699e245cf0a1eeaea4d73ab12051802ec2bcb3a4 Mon Sep 17 00:00:00 2001 From: Manus Date: Tue, 5 May 2026 05:58:18 -0400 Subject: [PATCH] =?UTF-8?q?fix:=20afficher=20le=20nom=20du=20signataire=20?= =?UTF-8?q?BAP=20m=C3=AAme=20sans=20image=20de=20signature=20(fallback=20t?= =?UTF-8?q?exte)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/bapCartouche.ts | 53 +++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/server/bapCartouche.ts b/server/bapCartouche.ts index a8cf0f4..5556bcd 100644 --- a/server/bapCartouche.ts +++ b/server/bapCartouche.ts @@ -183,34 +183,49 @@ export async function drawBapCartouche( }); // ── Signature ───────────────────────────────────────────────────────────── - if (data.signatureImageBytes && data.signatureName) { + if (data.signatureName) { try { - const mimeType = data.signatureMimeType || "image/png"; - const embeddedSig = - mimeType === "image/png" - ? await pdfDoc.embedPng(data.signatureImageBytes) - : await pdfDoc.embedJpg(data.signatureImageBytes); - const sigWidth = Math.min(rightColW - 10, 110); - const sigHeight = Math.round(sigWidth * 0.45); const sigX = rightColX + (rightColW - sigWidth) / 2; - const sigY = zoneY + 35; - targetPage.drawImage(embeddedSig, { - x: sigX, - y: sigY, - width: sigWidth, - height: sigHeight, - }); + // Afficher l'image si disponible + if (data.signatureImageBytes) { + const mimeType = data.signatureMimeType || "image/png"; + const embeddedSig = + mimeType === "image/png" + ? await pdfDoc.embedPng(data.signatureImageBytes) + : await pdfDoc.embedJpg(data.signatureImageBytes); - const nameW = fontNormal.widthOfTextAtSize(data.signatureName, 8); + const sigHeight = Math.round(sigWidth * 0.45); + const sigY = zoneY + 35; + + targetPage.drawImage(embeddedSig, { + x: sigX, + y: sigY, + width: sigWidth, + height: sigHeight, + }); + } + + // Toujours afficher le nom du signataire + const nameW = fontNormal.widthOfTextAtSize(data.signatureName, 9); targetPage.drawText(data.signatureName, { - x: sigX + (sigWidth - nameW) / 2, + x: rightColX + (rightColW - nameW) / 2, y: zoneY + 22, - size: 8, + size: 9, font: fontNormal, - color: rgb(0.3, 0.3, 0.3), + color: rgb(0.1, 0.1, 0.4), }); + + // Ligne de signature si pas d'image + if (!data.signatureImageBytes) { + targetPage.drawLine({ + start: { x: rightColX + 10, y: zoneY + 35 }, + end: { x: rightColX + rightColW - 10, y: zoneY + 35 }, + thickness: 0.5, + color: rgb(0.5, 0.5, 0.5), + }); + } } catch (_) { /* ignore signature errors */ }