Textfeld für Unterschriftoverlay und gitignore

This commit is contained in:
2026-01-16 14:14:38 +00:00
parent 2e96470a60
commit ba767a374a
5 changed files with 269 additions and 3 deletions

View File

@@ -16,6 +16,10 @@ let signatureDataUrl = null;
let signaturePos = { x: 0.5, y: 0.1 }; // Relative position (0-1)
let signatureScale = 0.3;
// Text overlay state (now part of signature overlay)
let textOverlayText = '';
let textFontSize = 14;
// WebSocket connection
let ws = null;
@@ -114,6 +118,10 @@ document.getElementById('pdfInput').addEventListener('change', async (e) => {
document.getElementById('uploadSection').style.display = 'none';
document.getElementById('statusSection').style.display = 'block';
// Show text input section and update with current date
document.getElementById('textInputSection').style.display = 'block';
updateTextInputWithDate();
// Show signature placeholder
document.getElementById('signaturePlaceholder').style.display = 'block';
@@ -298,6 +306,9 @@ async function renderPdfPreview(pdfBytes, pageNum = 1) {
placeholder.style.display = 'none';
}
}
// Update text in overlay if it exists
updateTextInOverlay();
}, 300); // Increased delay to ensure canvas is ready
console.log('PDF Seite', pageNum, 'erfolgreich gerendert');
@@ -504,6 +515,7 @@ async function changePage(direction) {
console.log('Overlay nach Seitenwechsel positioniert:', overlay.style.left, overlay.style.top);
}
}
}, 100);
// Send page change to signature station
@@ -567,6 +579,9 @@ async function showSignatureOverlay(signatureDataUrl) {
overlay.style.position = 'absolute'; // Ensure positioning works
overlay.style.zIndex = '10'; // Ensure it's on top
// Update text in overlay if text input has value
updateTextInOverlay();
document.getElementById('signatureControls').classList.add('show');
// Show page selector if multi-page
@@ -779,7 +794,7 @@ async function addSignatureToPdf() {
// Embed signature image once
const signatureImage = await pdfLibDoc.embedPng(signatureDataUrl);
// Add signature to each selected page
// Add signature and text to each selected page
for (const pageNum of pagesToSign) {
const page = pages[pageNum - 1]; // 0-indexed
const { width, height } = page.getSize();
@@ -818,6 +833,28 @@ async function addSignatureToPdf() {
});
console.log('✓ Unterschrift zu Seite', pageNum, 'hinzugefügt');
// Add text overlay if it exists (text is part of signature overlay, positioned top-left)
if (textOverlayText) {
// Text is positioned relative to signature overlay (top-left)
// Calculate text position: overlay left position + small offset, overlay top position - small offset
const textOffsetX = 5 * scaleX; // 5px offset from left
const textOffsetY = -5 * scaleY; // 5px offset from top (negative because PDF y is bottom-up)
const textX = x + textOffsetX;
// overlayTop is from top of canvas, convert to PDF coordinates (bottom-up)
const overlayTopInPdf = height - (overlayTop * scaleY);
const textY = overlayTopInPdf + textOffsetY; // Top of overlay - small offset
// Add text to page
page.drawText(textOverlayText, {
x: textX,
y: textY,
size: textFontSize * scaleY,
color: rgb(0, 0, 0),
});
console.log('✓ Text zu Seite', pageNum, 'hinzugefügt');
}
}
// Save PDF
@@ -846,6 +883,38 @@ async function addSignatureToPdf() {
}
}
function getCurrentDateString() {
const today = new Date();
const day = String(today.getDate()).padStart(2, '0');
const month = String(today.getMonth() + 1).padStart(2, '0');
const year = today.getFullYear();
return `${day}.${month}.${year}`;
}
function updateTextInputWithDate() {
const textInput = document.getElementById('textInput');
if (textInput) {
const currentDate = getCurrentDateString();
textInput.value = `Abgeholt am ${currentDate} durch:`;
}
}
function updateTextInOverlay() {
const textInput = document.getElementById('textInput');
const text = textInput ? textInput.value : '';
textOverlayText = text;
const textOverlayContent = document.getElementById('textOverlayContent');
if (textOverlayContent) {
if (text && text.trim()) {
textOverlayContent.textContent = text;
textOverlayContent.style.display = 'block';
} else {
textOverlayContent.style.display = 'none';
}
}
}
function removeSignatureOverlay() {
// Only remove the overlay, keep signedPdfBytes intact
const overlay = document.getElementById('signatureOverlay');
@@ -853,6 +922,12 @@ function removeSignatureOverlay() {
overlay.style.display = 'none'; // Explicitly hide overlay
document.getElementById('signatureControls').classList.remove('show');
// Hide text in overlay
const textOverlayContent = document.getElementById('textOverlayContent');
if (textOverlayContent) {
textOverlayContent.style.display = 'none';
}
// Reset placeholder to default state
const placeholder = document.getElementById('signaturePlaceholder');
const placeholderImg = document.getElementById('placeholderSignatureImage');
@@ -1003,9 +1078,15 @@ document.getElementById('downloadButton').addEventListener('click', async () =>
// Reset for next PDF
document.getElementById('uploadSection').style.display = 'block';
document.getElementById('statusSection').style.display = 'none';
// Hide text input section
document.getElementById('textInputSection').style.display = 'none';
// Reset file input
document.getElementById('pdfInput').value = '';
// Reset text input to default with current date
updateTextInputWithDate();
// Reset place signature button
const placeBtn = document.getElementById('placeSignatureButton');
@@ -1029,6 +1110,7 @@ document.getElementById('downloadButton').addEventListener('click', async () =>
pdfFileName = '';
pdfDoc = null;
currentPage = null;
textOverlayText = '';
console.log('Alles zurückgesetzt für nächste PDF');
} catch (error) {
@@ -1043,9 +1125,15 @@ function resetToStart() {
// Show upload section, hide status section
document.getElementById('uploadSection').style.display = 'block';
document.getElementById('statusSection').style.display = 'none';
// Hide text input section
document.getElementById('textInputSection').style.display = 'none';
// Reset file input
document.getElementById('pdfInput').value = '';
// Reset text input to default with current date
updateTextInputWithDate();
// Reset place signature button
const placeBtn = document.getElementById('placeSignatureButton');
@@ -1079,6 +1167,10 @@ function resetToStart() {
pdfDoc = null;
currentPage = null;
signatureDataUrl = null;
textOverlayText = '';
// Reset text input to default with current date
updateTextInputWithDate();
console.log('Zurück zum Anfang - bereit für neue PDF');
}
@@ -1112,5 +1204,15 @@ document.addEventListener('DOMContentLoaded', () => {
}
});
// Update text in overlay when text input changes
document.addEventListener('DOMContentLoaded', () => {
const textInput = document.getElementById('textInput');
if (textInput) {
textInput.addEventListener('input', () => {
updateTextInOverlay();
});
}
});
// Connect WebSocket on load
connectWebSocket();