[chore:] sender address usage in PdfBuilder.cs
This commit is contained in:
@@ -12,6 +12,7 @@ public class PdfBuilder
|
|||||||
private const int CellsPerRow = 3;
|
private const int CellsPerRow = 3;
|
||||||
private const int CellsPerPage = 21; // 3 columns × 7 rows
|
private const int CellsPerPage = 21; // 3 columns × 7 rows
|
||||||
private readonly XFont _boldFont = new("Arial", 9, XFontStyleEx.Bold);
|
private readonly XFont _boldFont = new("Arial", 9, XFontStyleEx.Bold);
|
||||||
|
private readonly XFont _smallFont = new("Arial", 6, XFontStyleEx.Regular);
|
||||||
private readonly double _cellHeight = 42.43; // mm
|
private readonly double _cellHeight = 42.43; // mm
|
||||||
private readonly double _cellPaddingBottom = 5; // mm
|
private readonly double _cellPaddingBottom = 5; // mm
|
||||||
|
|
||||||
@@ -50,8 +51,29 @@ public class PdfBuilder
|
|||||||
|
|
||||||
// Generate markdown addresses from all KasPersons in the set
|
// Generate markdown addresses from all KasPersons in the set
|
||||||
var addresses = new string?[addressSet.KasPersons.Count];
|
var addresses = new string?[addressSet.KasPersons.Count];
|
||||||
|
|
||||||
|
// find customer (owner) to include sender_address
|
||||||
|
string senderLine = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var owner = Settings._instance.customers.customers.FirstOrDefault(c => c.ID == addressSet.owner_id);
|
||||||
|
if (owner != null && !string.IsNullOrWhiteSpace(owner.sender_address))
|
||||||
|
// ensure single line and wrap in a small-font tag
|
||||||
|
senderLine = "<font6>" + owner.sender_address.Replace("\n", " ").Trim() + "</font6>\n";
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
senderLine = null;
|
||||||
|
}
|
||||||
|
|
||||||
for (var i = 0; i < addressSet.KasPersons.Count; i++)
|
for (var i = 0; i < addressSet.KasPersons.Count; i++)
|
||||||
addresses[i] = AddressCreator.CreateFinalMarkdownString(addressSet.KasPersons[i].refsid);
|
{
|
||||||
|
var addr = AddressCreator.CreateFinalMarkdownString(addressSet.KasPersons[i].refsid);
|
||||||
|
if (!string.IsNullOrEmpty(senderLine))
|
||||||
|
addresses[i] = senderLine + (addr ?? "");
|
||||||
|
else
|
||||||
|
addresses[i] = addr;
|
||||||
|
}
|
||||||
|
|
||||||
CreateAddressLabelPdf(addresses, outputPath);
|
CreateAddressLabelPdf(addresses, outputPath);
|
||||||
}
|
}
|
||||||
@@ -75,8 +97,28 @@ public class PdfBuilder
|
|||||||
|
|
||||||
// Generate markdown addresses from all KasPersons in the set
|
// Generate markdown addresses from all KasPersons in the set
|
||||||
var addresses = new string?[addressSet.KasPersons.Count];
|
var addresses = new string?[addressSet.KasPersons.Count];
|
||||||
|
|
||||||
|
// find customer (owner) to include sender_address
|
||||||
|
string senderLine = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var owner = Settings._instance.customers.customers.FirstOrDefault(c => c.ID == addressSet.owner_id);
|
||||||
|
if (owner != null && !string.IsNullOrWhiteSpace(owner.sender_address))
|
||||||
|
senderLine = "<font6>" + owner.sender_address.Replace("\n", " ").Trim() + "</font6>\n";
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
senderLine = null;
|
||||||
|
}
|
||||||
|
|
||||||
for (var i = 0; i < addressSet.KasPersons.Count; i++)
|
for (var i = 0; i < addressSet.KasPersons.Count; i++)
|
||||||
addresses[i] = AddressCreator.CreateFinalMarkdownString(addressSet.KasPersons[i].refsid);
|
{
|
||||||
|
var addr = AddressCreator.CreateFinalMarkdownString(addressSet.KasPersons[i].refsid);
|
||||||
|
if (!string.IsNullOrEmpty(senderLine))
|
||||||
|
addresses[i] = senderLine + (addr ?? "");
|
||||||
|
else
|
||||||
|
addresses[i] = addr;
|
||||||
|
}
|
||||||
|
|
||||||
CreateAddressLabelPdfWithPlaceholder(addresses, placeholderText, outputPath);
|
CreateAddressLabelPdfWithPlaceholder(addresses, placeholderText, outputPath);
|
||||||
}
|
}
|
||||||
@@ -233,10 +275,8 @@ public class PdfBuilder
|
|||||||
// Calculate total height of the text block
|
// Calculate total height of the text block
|
||||||
var totalHeight = lines.Length * lineHeight;
|
var totalHeight = lines.Length * lineHeight;
|
||||||
|
|
||||||
// Start drawing from the lower-left corner of the cell
|
// Start drawing from the top of the cell (align addresses to top)
|
||||||
var startY = y + cellHeight - paddingBottomPoints - totalHeight;
|
var startY = y + paddingTopPoints;
|
||||||
if (startY < y + paddingTopPoints)
|
|
||||||
startY = y + paddingTopPoints; // don't overflow top padding
|
|
||||||
|
|
||||||
var currentY = startY;
|
var currentY = startY;
|
||||||
|
|
||||||
@@ -259,6 +299,27 @@ public class PdfBuilder
|
|||||||
|
|
||||||
while (i < line.Length)
|
while (i < line.Length)
|
||||||
{
|
{
|
||||||
|
// Check for small-font tag <font6> ... </font6>
|
||||||
|
if (i <= line.Length - 7 && line.Substring(i, 7) == "<font6>")
|
||||||
|
{
|
||||||
|
var endTag = line.IndexOf("</font6>", i + 7, StringComparison.Ordinal);
|
||||||
|
if (endTag != -1)
|
||||||
|
{
|
||||||
|
var inner = line.Substring(i + 7, endTag - (i + 7));
|
||||||
|
if (!string.IsNullOrEmpty(inner))
|
||||||
|
{
|
||||||
|
gfx.DrawString(inner, _smallFont, XBrushes.Black,
|
||||||
|
new XRect(currentX, y, maxWidth - (currentX - x), _smallFont.Size * 1.2),
|
||||||
|
XStringFormats.TopLeft);
|
||||||
|
var measuredSmall = gfx.MeasureString(inner, _smallFont);
|
||||||
|
currentX += measuredSmall.Width;
|
||||||
|
}
|
||||||
|
|
||||||
|
i = endTag + 8; // move past </font6>
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Check for bold marker (**)
|
// Check for bold marker (**)
|
||||||
if (i < line.Length - 1 && line[i] == '*' && line[i + 1] == '*')
|
if (i < line.Length - 1 && line[i] == '*' && line[i + 1] == '*')
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user