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"
|
@onmousedown:preventDefault="true"
|
||||||
@onclick:stopPropagation="true">
|
@onclick:stopPropagation="true">
|
||||||
<span class="sender-image-editor__field-label">@field.ReceiverName</span>
|
<span class="sender-image-editor__field-label">@field.ReceiverName</span>
|
||||||
<button type="button"
|
@if (ShowFieldRemoveButton)
|
||||||
class="sender-image-editor__field-remove"
|
{
|
||||||
title='@L("Delete", "Löschen")'
|
<button type="button"
|
||||||
draggable="false"
|
class="sender-image-editor__field-remove"
|
||||||
@onclick:stopPropagation="true"
|
title='@L("Delete", "Löschen")'
|
||||||
@onclick="() => RemoveField.InvokeAsync(field.Index)">
|
draggable="false"
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 16 16" fill="none" aria-hidden="true">
|
@onclick:stopPropagation="true"
|
||||||
<path d="M4 4L12 12M12 4L4 12" stroke="currentColor" stroke-width="2" stroke-linecap="round" />
|
@onclick="() => RemoveField.InvokeAsync(field.Index)">
|
||||||
</svg>
|
<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 16 16" fill="none" aria-hidden="true">
|
||||||
</button>
|
<path d="M4 4L12 12M12 4L4 12" stroke="currentColor" stroke-width="2" stroke-linecap="round" />
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
@@ -132,6 +135,9 @@
|
|||||||
[Parameter]
|
[Parameter]
|
||||||
public IReadOnlyList<SenderPdfFieldOverlay> Fields { get; set; } = Array.Empty<SenderPdfFieldOverlay>();
|
public IReadOnlyList<SenderPdfFieldOverlay> Fields { get; set; } = Array.Empty<SenderPdfFieldOverlay>();
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public bool ShowFieldRemoveButton { get; set; } = true;
|
||||||
|
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public EventCallback<MouseEventArgs> EditorClick { get; set; }
|
public EventCallback<MouseEventArgs> EditorClick { get; set; }
|
||||||
|
|
||||||
@@ -235,6 +241,9 @@
|
|||||||
|
|
||||||
private async Task OnFieldMouseDownAsync(MouseEventArgs args, SenderPdfFieldOverlay field)
|
private async Task OnFieldMouseDownAsync(MouseEventArgs args, SenderPdfFieldOverlay field)
|
||||||
{
|
{
|
||||||
|
if (!MoveField.HasDelegate)
|
||||||
|
return;
|
||||||
|
|
||||||
var coords = await JSRuntime.InvokeAsync<EditorCoords?>(
|
var coords = await JSRuntime.InvokeAsync<EditorCoords?>(
|
||||||
"envelopeEditor.getClickCoordsOnPdfPage",
|
"envelopeEditor.getClickCoordsOnPdfPage",
|
||||||
"sender-editor-pdf-viewer",
|
"sender-editor-pdf-viewer",
|
||||||
|
|||||||
@@ -12,7 +12,6 @@
|
|||||||
@using EnvelopeGenerator.Domain.Constants
|
@using EnvelopeGenerator.Domain.Constants
|
||||||
@using Microsoft.JSInterop
|
@using Microsoft.JSInterop
|
||||||
@using DevExpress.Blazor
|
@using DevExpress.Blazor
|
||||||
@using System.Drawing
|
|
||||||
@using System.Security.Claims
|
@using System.Security.Claims
|
||||||
@using System.ComponentModel.DataAnnotations
|
@using System.ComponentModel.DataAnnotations
|
||||||
@using Microsoft.Extensions.Caching.Memory
|
@using Microsoft.Extensions.Caching.Memory
|
||||||
@@ -195,7 +194,9 @@
|
|||||||
PageCount="@_pageCount"
|
PageCount="@_pageCount"
|
||||||
Pages="@_pagePreviews"
|
Pages="@_pagePreviews"
|
||||||
PdfDataUrl="@PdfDataUrl"
|
PdfDataUrl="@PdfDataUrl"
|
||||||
PdfFileName="@PdfFileName" />
|
PdfFileName="@PdfFileName"
|
||||||
|
Fields="@FieldOverlays"
|
||||||
|
ShowFieldRemoveButton="false" />
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -386,6 +387,10 @@
|
|||||||
EnvelopeGenerator.Application.Common.Dto.EnvelopeReceiver.EnvelopeReceiverDto? _envelopeReceiver;
|
EnvelopeGenerator.Application.Common.Dto.EnvelopeReceiver.EnvelopeReceiverDto? _envelopeReceiver;
|
||||||
ClaimsPrincipal? _receiverUser;
|
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 }
|
string? PdfDataUrl => _displayPdfBytes is { Length: > 0 }
|
||||||
? $"data:application/pdf;base64,{Convert.ToBase64String(_displayPdfBytes)}"
|
? $"data:application/pdf;base64,{Convert.ToBase64String(_displayPdfBytes)}"
|
||||||
: null;
|
: null;
|
||||||
@@ -560,9 +565,7 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_displayPdfBytes = _signatures.Count > 0
|
_displayPdfBytes = _pdfBytes;
|
||||||
? DrawSignaturePlaceholders(_pdfBytes, _signatures)
|
|
||||||
: _pdfBytes;
|
|
||||||
|
|
||||||
_pagePreviews = (await PdfPageImageRenderer.RenderPagesAsImagesAsync(_displayPdfBytes))
|
_pagePreviews = (await PdfPageImageRenderer.RenderPagesAsImagesAsync(_displayPdfBytes))
|
||||||
.OrderBy(p => p.PageNumber)
|
.OrderBy(p => p.PageNumber)
|
||||||
@@ -618,68 +621,6 @@
|
|||||||
h.Status is EnvelopeStatus.DocumentRejected or EnvelopeStatus.EnvelopeRejected) == true;
|
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 -----
|
// ----- Signature popup handlers -----
|
||||||
void OpenSignaturePopup()
|
void OpenSignaturePopup()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -101,7 +101,8 @@
|
|||||||
PageCount="@_pageCount"
|
PageCount="@_pageCount"
|
||||||
Pages="@_pagePreviews"
|
Pages="@_pagePreviews"
|
||||||
PdfDataUrl="@PdfDataUrl"
|
PdfDataUrl="@PdfDataUrl"
|
||||||
PdfFileName="@PdfFileName" />
|
PdfFileName="@PdfFileName"
|
||||||
|
ShowFieldRemoveButton="false" />
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user