fix: afficher le nom du signataire BAP même sans image de signature (fallback texte)
This commit is contained in:
@@ -183,34 +183,49 @@ export async function drawBapCartouche(
|
|||||||
});
|
});
|
||||||
|
|
||||||
// ── Signature ─────────────────────────────────────────────────────────────
|
// ── Signature ─────────────────────────────────────────────────────────────
|
||||||
if (data.signatureImageBytes && data.signatureName) {
|
if (data.signatureName) {
|
||||||
try {
|
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 sigWidth = Math.min(rightColW - 10, 110);
|
||||||
const sigHeight = Math.round(sigWidth * 0.45);
|
|
||||||
const sigX = rightColX + (rightColW - sigWidth) / 2;
|
const sigX = rightColX + (rightColW - sigWidth) / 2;
|
||||||
const sigY = zoneY + 35;
|
|
||||||
|
|
||||||
targetPage.drawImage(embeddedSig, {
|
// Afficher l'image si disponible
|
||||||
x: sigX,
|
if (data.signatureImageBytes) {
|
||||||
y: sigY,
|
const mimeType = data.signatureMimeType || "image/png";
|
||||||
width: sigWidth,
|
const embeddedSig =
|
||||||
height: sigHeight,
|
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, {
|
targetPage.drawText(data.signatureName, {
|
||||||
x: sigX + (sigWidth - nameW) / 2,
|
x: rightColX + (rightColW - nameW) / 2,
|
||||||
y: zoneY + 22,
|
y: zoneY + 22,
|
||||||
size: 8,
|
size: 9,
|
||||||
font: fontNormal,
|
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 (_) {
|
} catch (_) {
|
||||||
/* ignore signature errors */
|
/* ignore signature errors */
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user