From 649d5b1e18f6fd21639d34f9e9c70a60f0040d0c Mon Sep 17 00:00:00 2001 From: Sosthene Date: Mon, 11 Aug 2025 11:43:27 +0200 Subject: [PATCH] French text for watermark + timestamp on images too --- src/front/Services/WatermarkService/index.ts | 33 +++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/front/Services/WatermarkService/index.ts b/src/front/Services/WatermarkService/index.ts index ebfc8ff5..13951879 100644 --- a/src/front/Services/WatermarkService/index.ts +++ b/src/front/Services/WatermarkService/index.ts @@ -1,5 +1,6 @@ export default class WatermarkService { private static instance: WatermarkService; + private watermarkText: string = 'Certifié par LeCoffre'; public static getInstance(): WatermarkService { if (!WatermarkService.instance) { @@ -142,18 +143,29 @@ export default class WatermarkService { ctx.save(); // Set watermark properties - ctx.fillStyle = 'rgba(128, 128, 128, 0.7)'; // Semi-transparent gray - ctx.font = '12px Arial'; + ctx.fillStyle = 'rgba(204, 51, 51, 0.7)'; // Semi-transparent pale red (matching PDF color) + ctx.font = '10px Arial'; ctx.textAlign = 'right'; ctx.textBaseline = 'bottom'; - // Position watermark in bottom-right corner - const text = 'Processed by LeCoffre'; - const x = width - 10; // 10 pixels from right edge - const y = height - 10; // 10 pixels from bottom + // Position watermark in bottom-right corner with timestamp + const dateTime = new Date().toLocaleString('fr-FR', { + year: 'numeric', + month: '2-digit', + day: '2-digit', + hour: '2-digit', + minute: '2-digit' + }); - // Add watermark text - ctx.fillText(text, x, y); + const lineHeight = 12; // Space between lines + const x = width - 20; // 20 pixels from right edge (matching PDF margins) + const y = 20; // 20 pixels from bottom (matching PDF margins) + + // Add watermark text (second line - top) + ctx.fillText(this.watermarkText, x, y + lineHeight); + + // Add date/time (first line - bottom) + ctx.fillText(dateTime, x, y); // Restore state ctx.restore(); @@ -168,7 +180,6 @@ export default class WatermarkService { const { width, height } = page.getSize(); // Calculate watermark position (bottom-right corner) - const text = 'Processed by LeCoffre'; const dateTime = new Date().toLocaleString('fr-FR', { year: 'numeric', month: '2-digit', @@ -182,7 +193,7 @@ export default class WatermarkService { // Calculate text widths (approximate - pdf-lib doesn't have a direct method for this) // Using a conservative estimate: ~6 points per character for 10pt font - const estimatedTextWidth1 = text.length * 6; + const estimatedTextWidth1 = this.watermarkText.length * 6; const estimatedTextWidth2 = dateTime.length * 6; const maxTextWidth = Math.max(estimatedTextWidth1, estimatedTextWidth2); @@ -191,7 +202,7 @@ export default class WatermarkService { const y = 20; // 20 points from bottom // Add watermark text with transparency (first line) - page.drawText(text, { + page.drawText(this.watermarkText, { x: x, y: y + lineHeight, // Second line (top) size: fontSize,