Add conditional field removal and overlay improvements
Updated `SenderPdfImageEditor` to conditionally display the "Remove" button using a new `ShowFieldRemoveButton` parameter. Integrated dynamic field overlays in `ReceiverPage` and `ReceiverSignedPage` using `SenderPdfFieldOverlay`. Removed `DrawSignaturePlaceholders` method and simplified `_displayPdfBytes` assignment. Added a guard clause in `OnFieldMouseDownAsync` to prevent unnecessary execution.
This commit is contained in:
@@ -93,16 +93,19 @@
|
||||
@onmousedown:preventDefault="true"
|
||||
@onclick:stopPropagation="true">
|
||||
<span class="sender-image-editor__field-label">@field.ReceiverName</span>
|
||||
<button type="button"
|
||||
class="sender-image-editor__field-remove"
|
||||
title='@L("Delete", "Löschen")'
|
||||
draggable="false"
|
||||
@onclick:stopPropagation="true"
|
||||
@onclick="() => RemoveField.InvokeAsync(field.Index)">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 16 16" fill="none" aria-hidden="true">
|
||||
<path d="M4 4L12 12M12 4L4 12" stroke="currentColor" stroke-width="2" stroke-linecap="round" />
|
||||
</svg>
|
||||
</button>
|
||||
@if (ShowFieldRemoveButton)
|
||||
{
|
||||
<button type="button"
|
||||
class="sender-image-editor__field-remove"
|
||||
title='@L("Delete", "Löschen")'
|
||||
draggable="false"
|
||||
@onclick:stopPropagation="true"
|
||||
@onclick="() => RemoveField.InvokeAsync(field.Index)">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 16 16" fill="none" aria-hidden="true">
|
||||
<path d="M4 4L12 12M12 4L4 12" stroke="currentColor" stroke-width="2" stroke-linecap="round" />
|
||||
</svg>
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
@@ -132,6 +135,9 @@
|
||||
[Parameter]
|
||||
public IReadOnlyList<SenderPdfFieldOverlay> Fields { get; set; } = Array.Empty<SenderPdfFieldOverlay>();
|
||||
|
||||
[Parameter]
|
||||
public bool ShowFieldRemoveButton { get; set; } = true;
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<MouseEventArgs> EditorClick { get; set; }
|
||||
|
||||
@@ -235,6 +241,9 @@
|
||||
|
||||
private async Task OnFieldMouseDownAsync(MouseEventArgs args, SenderPdfFieldOverlay field)
|
||||
{
|
||||
if (!MoveField.HasDelegate)
|
||||
return;
|
||||
|
||||
var coords = await JSRuntime.InvokeAsync<EditorCoords?>(
|
||||
"envelopeEditor.getClickCoordsOnPdfPage",
|
||||
"sender-editor-pdf-viewer",
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
@using EnvelopeGenerator.Domain.Constants
|
||||
@using Microsoft.JSInterop
|
||||
@using DevExpress.Blazor
|
||||
@using System.Drawing
|
||||
@using System.Security.Claims
|
||||
@using System.ComponentModel.DataAnnotations
|
||||
@using Microsoft.Extensions.Caching.Memory
|
||||
@@ -195,7 +194,9 @@
|
||||
PageCount="@_pageCount"
|
||||
Pages="@_pagePreviews"
|
||||
PdfDataUrl="@PdfDataUrl"
|
||||
PdfFileName="@PdfFileName" />
|
||||
PdfFileName="@PdfFileName"
|
||||
Fields="@FieldOverlays"
|
||||
ShowFieldRemoveButton="false" />
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
@@ -386,6 +387,10 @@
|
||||
EnvelopeGenerator.Application.Common.Dto.EnvelopeReceiver.EnvelopeReceiverDto? _envelopeReceiver;
|
||||
ClaimsPrincipal? _receiverUser;
|
||||
|
||||
IReadOnlyList<SenderPdfFieldOverlay> FieldOverlays => _signatures
|
||||
.Select((s, i) => new SenderPdfFieldOverlay(i, s.Page, s.X, s.Y, "UNTERSCHRIFT", "#4F46E5"))
|
||||
.ToList();
|
||||
|
||||
string? PdfDataUrl => _displayPdfBytes is { Length: > 0 }
|
||||
? $"data:application/pdf;base64,{Convert.ToBase64String(_displayPdfBytes)}"
|
||||
: null;
|
||||
@@ -560,9 +565,7 @@
|
||||
return;
|
||||
}
|
||||
|
||||
_displayPdfBytes = _signatures.Count > 0
|
||||
? DrawSignaturePlaceholders(_pdfBytes, _signatures)
|
||||
: _pdfBytes;
|
||||
_displayPdfBytes = _pdfBytes;
|
||||
|
||||
_pagePreviews = (await PdfPageImageRenderer.RenderPagesAsImagesAsync(_displayPdfBytes))
|
||||
.OrderBy(p => p.PageNumber)
|
||||
@@ -618,68 +621,6 @@
|
||||
h.Status is EnvelopeStatus.DocumentRejected or EnvelopeStatus.EnvelopeRejected) == true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Uses PdfSharp to draw a visible signature placeholder box on every signature field.
|
||||
/// sig.X / sig.Y come from GetSignaturesAsync(UnitOfLength.Point) → already in PDF points.
|
||||
/// PdfSharp coordinate origin: bottom-left, Y up. Conversion: pdfY = pageH - sigY - sigH
|
||||
/// Signature field size (fixed): 1.77" × 1.96" = 127.44pt × 141.12pt
|
||||
/// </summary>
|
||||
static byte[] DrawSignaturePlaceholders(
|
||||
byte[] pdfBytes,
|
||||
IReadOnlyList<SignatureDto> signatures)
|
||||
{
|
||||
if (signatures.Count == 0) return pdfBytes;
|
||||
|
||||
using var inputMs = new System.IO.MemoryStream(pdfBytes);
|
||||
using var outputMs = new System.IO.MemoryStream();
|
||||
|
||||
var document = PdfSharp.Pdf.IO.PdfReader.Open(
|
||||
inputMs,
|
||||
PdfSharp.Pdf.IO.PdfDocumentOpenMode.Modify);
|
||||
|
||||
const double sigW = 1.77 * 72; // 127.44 pt
|
||||
const double sigH = 1.96 * 72; // 141.12 pt
|
||||
|
||||
foreach (var sig in signatures)
|
||||
{
|
||||
int pageIndex = sig.Page - 1;
|
||||
if (pageIndex < 0 || pageIndex >= document.PageCount) continue;
|
||||
|
||||
var page = document.Pages[pageIndex];
|
||||
|
||||
// PdfSharp XGraphics uses top-left origin, Y down — same as sig.X/sig.Y
|
||||
// No coordinate conversion needed.
|
||||
using var gfx = PdfSharp.Drawing.XGraphics.FromPdfPage(page);
|
||||
|
||||
var rect = new PdfSharp.Drawing.XRect(sig.X, sig.Y, sigW, sigH);
|
||||
|
||||
// Filled semi-transparent rectangle
|
||||
var fillBrush = new PdfSharp.Drawing.XSolidBrush(
|
||||
PdfSharp.Drawing.XColor.FromArgb(40, 60, 80, 160));
|
||||
var borderPen = new PdfSharp.Drawing.XPen(
|
||||
PdfSharp.Drawing.XColor.FromArgb(200, 60, 80, 200), 1.5);
|
||||
|
||||
gfx.DrawRectangle(fillBrush, rect);
|
||||
gfx.DrawRectangle(borderPen, rect);
|
||||
|
||||
// "UNTERSCHRIFT" label centred in the box
|
||||
var font = new PdfSharp.Drawing.XFont("Arial", 9,
|
||||
PdfSharp.Drawing.XFontStyleEx.Bold);
|
||||
var textBrush = new PdfSharp.Drawing.XSolidBrush(
|
||||
PdfSharp.Drawing.XColor.FromArgb(200, 40, 60, 140));
|
||||
|
||||
var textFmt = new PdfSharp.Drawing.XStringFormat
|
||||
{
|
||||
Alignment = PdfSharp.Drawing.XStringAlignment.Center,
|
||||
LineAlignment = PdfSharp.Drawing.XLineAlignment.Center,
|
||||
};
|
||||
gfx.DrawString("UNTERSCHRIFT", font, textBrush, rect, textFmt);
|
||||
}
|
||||
|
||||
document.Save(outputMs);
|
||||
return outputMs.ToArray();
|
||||
}
|
||||
|
||||
// ----- Signature popup handlers -----
|
||||
void OpenSignaturePopup()
|
||||
{
|
||||
|
||||
@@ -101,7 +101,8 @@
|
||||
PageCount="@_pageCount"
|
||||
Pages="@_pagePreviews"
|
||||
PdfDataUrl="@PdfDataUrl"
|
||||
PdfFileName="@PdfFileName" />
|
||||
PdfFileName="@PdfFileName"
|
||||
ShowFieldRemoveButton="false" />
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user