diff --git a/EnvelopeGenerator.Server/EnvelopeGenerator.Server/Components/Pages/EnvelopeReceiverReportSignedPage.razor b/EnvelopeGenerator.Server/EnvelopeGenerator.Server/Components/Pages/EnvelopeReceiverReportSignedPage.razor index b4eaec17..65e1a3a2 100644 --- a/EnvelopeGenerator.Server/EnvelopeGenerator.Server/Components/Pages/EnvelopeReceiverReportSignedPage.razor +++ b/EnvelopeGenerator.Server/EnvelopeGenerator.Server/Components/Pages/EnvelopeReceiverReportSignedPage.razor @@ -206,19 +206,18 @@ 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 - const double imgRatio = 0.52; // top 52% = image (was 0.60) - const double textRatio = 0.43; // bottom 43% = text (was 0.38) + const double sigW = 1.77 * 72; // 127.44 pt + const double sigH = 1.96 * 72; // 141.12 pt + const double imgRatio = 0.52; // top 52% = image + const double lineH = 11.5; // fixed row height matching font size (bold 7.5pt + normal 6.5pt) + const double bgPad = 3.0; // background box padding around content (pt) var black = PdfSharp.Drawing.XColor.FromArgb(255, 20, 20, 20); var darkGray = PdfSharp.Drawing.XColor.FromArgb(255, 80, 80, 80); var lineColor = PdfSharp.Drawing.XColor.FromArgb(180, 100, 100, 120); - // Background: paper/cream tone, no border var bgColor = PdfSharp.Drawing.XColor.FromArgb(255, 255, 253, 240); var bgBrush = new PdfSharp.Drawing.XSolidBrush(bgColor); - const double bgPad = 3.0; // extra padding around the signature box (pt) var fontBold = new PdfSharp.Drawing.XFont("Arial", 7.5, PdfSharp.Drawing.XFontStyleEx.Bold); var fontNormal = new PdfSharp.Drawing.XFont("Arial", 6.5, PdfSharp.Drawing.XFontStyleEx.Regular); @@ -244,44 +243,52 @@ double x = field.X; double y = field.Y; - // --- Background rectangle (drawn first, sits between PDF and signature) --- - var bgRect = new PdfSharp.Drawing.XRect(x - bgPad, y - bgPad, sigW + bgPad * 2, sigH + bgPad * 2); + // --- Calculate layout positions first (needed for bg rect) --- + double imgH = sigH * imgRatio; + double lineY = y + imgH + 1.0; // 1pt gap between image and separator + double textY = lineY + 1.5; // 1.5pt gap below separator line + double padding = 3; + + // Row 1: FullName + double row1Y = textY; + // Row 2: Position (optional) + double row2Y = row1Y + lineH; + // Row 3: Place, Date — immediately after row2 regardless of position + double row3Y = !string.IsNullOrWhiteSpace(sig.Position) ? row2Y + lineH : row2Y; + double contentBottom = row3Y + lineH; + + // --- Background rectangle sized to actual content (not full sigH) --- + var bgRect = new PdfSharp.Drawing.XRect( + x - bgPad, + y - bgPad, + sigW + bgPad * 2, + (contentBottom - y) + bgPad * 2); gfx.DrawRectangle(bgBrush, bgRect); // --- Image area --- - double imgH = sigH * imgRatio; - var imgRect = new PdfSharp.Drawing.XRect(x, y, sigW, imgH); - + var imgRect = new PdfSharp.Drawing.XRect(x, y, sigW, imgH); using var imgStream = new System.IO.MemoryStream(imgBytes); var xImg = PdfSharp.Drawing.XImage.FromStream(imgStream); gfx.DrawImage(xImg, imgRect); // --- Separator line --- - double lineY = y + imgH + sigH * 0.005; // was 0.01 — tighter gap after image gfx.DrawLine(linePen, x + 2, lineY, x + sigW - 2, lineY); - // --- Text area --- - double textY = lineY + 1; // was +2 — tighter gap below line - double textH = sigH * textRatio; - double lineH = textH / 3.0; // was /3.5 — rows closer together - double padding = 3; - + // --- Text rows --- // Row 1: FullName (bold) - var nameRect = new PdfSharp.Drawing.XRect(x + padding, textY, sigW - padding * 2, lineH); + var nameRect = new PdfSharp.Drawing.XRect(x + padding, row1Y, sigW - padding * 2, lineH); gfx.DrawString(sig.FullName, fontBold, new PdfSharp.Drawing.XSolidBrush(black), nameRect, fmtLeft); // Row 2: Position (optional) - double row2Y = textY + lineH; if (!string.IsNullOrWhiteSpace(sig.Position)) { var posRect = new PdfSharp.Drawing.XRect(x + padding, row2Y, sigW - padding * 2, lineH); gfx.DrawString(sig.Position, fontNormal, new PdfSharp.Drawing.XSolidBrush(darkGray), posRect, fmtLeft); - row2Y += lineH; } - // Row 3 (or 2 if no position): Place, Date + // Row 3: Place, Date var placeDate = $"{sig.Place}, {date}"; - var dateRect = new PdfSharp.Drawing.XRect(x + padding, row2Y, sigW - padding * 2, lineH); + var dateRect = new PdfSharp.Drawing.XRect(x + padding, row3Y, sigW - padding * 2, lineH); gfx.DrawString(placeDate, fontNormal, new PdfSharp.Drawing.XSolidBrush(darkGray), dateRect, fmtLeft); }