French text for watermark + timestamp on images too
This commit is contained in:
parent
75f5a9a9be
commit
649d5b1e18
@ -1,5 +1,6 @@
|
|||||||
export default class WatermarkService {
|
export default class WatermarkService {
|
||||||
private static instance: WatermarkService;
|
private static instance: WatermarkService;
|
||||||
|
private watermarkText: string = 'Certifié par LeCoffre';
|
||||||
|
|
||||||
public static getInstance(): WatermarkService {
|
public static getInstance(): WatermarkService {
|
||||||
if (!WatermarkService.instance) {
|
if (!WatermarkService.instance) {
|
||||||
@ -142,18 +143,29 @@ export default class WatermarkService {
|
|||||||
ctx.save();
|
ctx.save();
|
||||||
|
|
||||||
// Set watermark properties
|
// Set watermark properties
|
||||||
ctx.fillStyle = 'rgba(128, 128, 128, 0.7)'; // Semi-transparent gray
|
ctx.fillStyle = 'rgba(204, 51, 51, 0.7)'; // Semi-transparent pale red (matching PDF color)
|
||||||
ctx.font = '12px Arial';
|
ctx.font = '10px Arial';
|
||||||
ctx.textAlign = 'right';
|
ctx.textAlign = 'right';
|
||||||
ctx.textBaseline = 'bottom';
|
ctx.textBaseline = 'bottom';
|
||||||
|
|
||||||
// Position watermark in bottom-right corner
|
// Position watermark in bottom-right corner with timestamp
|
||||||
const text = 'Processed by LeCoffre';
|
const dateTime = new Date().toLocaleString('fr-FR', {
|
||||||
const x = width - 10; // 10 pixels from right edge
|
year: 'numeric',
|
||||||
const y = height - 10; // 10 pixels from bottom
|
month: '2-digit',
|
||||||
|
day: '2-digit',
|
||||||
|
hour: '2-digit',
|
||||||
|
minute: '2-digit'
|
||||||
|
});
|
||||||
|
|
||||||
// Add watermark text
|
const lineHeight = 12; // Space between lines
|
||||||
ctx.fillText(text, x, y);
|
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
|
// Restore state
|
||||||
ctx.restore();
|
ctx.restore();
|
||||||
@ -168,7 +180,6 @@ export default class WatermarkService {
|
|||||||
const { width, height } = page.getSize();
|
const { width, height } = page.getSize();
|
||||||
|
|
||||||
// Calculate watermark position (bottom-right corner)
|
// Calculate watermark position (bottom-right corner)
|
||||||
const text = 'Processed by LeCoffre';
|
|
||||||
const dateTime = new Date().toLocaleString('fr-FR', {
|
const dateTime = new Date().toLocaleString('fr-FR', {
|
||||||
year: 'numeric',
|
year: 'numeric',
|
||||||
month: '2-digit',
|
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)
|
// 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
|
// 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 estimatedTextWidth2 = dateTime.length * 6;
|
||||||
const maxTextWidth = Math.max(estimatedTextWidth1, estimatedTextWidth2);
|
const maxTextWidth = Math.max(estimatedTextWidth1, estimatedTextWidth2);
|
||||||
|
|
||||||
@ -191,7 +202,7 @@ export default class WatermarkService {
|
|||||||
const y = 20; // 20 points from bottom
|
const y = 20; // 20 points from bottom
|
||||||
|
|
||||||
// Add watermark text with transparency (first line)
|
// Add watermark text with transparency (first line)
|
||||||
page.drawText(text, {
|
page.drawText(this.watermarkText, {
|
||||||
x: x,
|
x: x,
|
||||||
y: y + lineHeight, // Second line (top)
|
y: y + lineHeight, // Second line (top)
|
||||||
size: fontSize,
|
size: fontSize,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user