Improve PDF font handling; simplify report SQL fields

Enhanced PDFBurner to use a static FontProvider for better font support when rendering form field values. In ReportCreator, removed unused HEAD_TITLE and HEAD_SUBJECT fields from the SQL query and related mapping, streamlining report item loading.
This commit is contained in:
2026-01-22 15:57:09 +01:00
parent 7e5ff6bcb2
commit b20260674e
2 changed files with 20 additions and 7 deletions

View File

@@ -7,6 +7,8 @@ using iText.Kernel.Pdf;
using iText.Kernel.Pdf.Canvas; using iText.Kernel.Pdf.Canvas;
using iText.Layout; using iText.Layout;
using iText.Layout.Element; using iText.Layout.Element;
using iText.Layout.Font;
using iText.Layout.Properties;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Logging.Abstractions;
using Newtonsoft.Json; using Newtonsoft.Json;
@@ -17,6 +19,7 @@ namespace EnvelopeGenerator.Jobs.FinalizeDocument;
public class PDFBurner public class PDFBurner
{ {
private static readonly FontProvider FontProvider = CreateFontProvider();
private readonly ILogger<PDFBurner> _logger; private readonly ILogger<PDFBurner> _logger;
private readonly PDFBurnerParams _pdfBurnerParams; private readonly PDFBurnerParams _pdfBurnerParams;
@@ -160,6 +163,14 @@ public class PDFBurner
} }
} }
private static FontProvider CreateFontProvider()
{
var provider = new FontProvider();
provider.AddStandardPdfFonts();
provider.AddSystemFonts();
return provider;
}
private void AddFormFieldValue(PdfDocument pdf, Annotation annotation, string value) private void AddFormFieldValue(PdfDocument pdf, Annotation annotation, string value)
{ {
var bounds = annotation.bbox.Select(ToInches).ToList(); var bounds = annotation.bbox.Select(ToInches).ToList();
@@ -170,6 +181,9 @@ public class PDFBurner
var page = pdf.GetPage(annotation.pageIndex + 1); var page = pdf.GetPage(annotation.pageIndex + 1);
var canvas = new Canvas(new PdfCanvas(page), page.GetPageSize()); var canvas = new Canvas(new PdfCanvas(page), page.GetPageSize());
canvas.SetProperty(Property.FONT_PROVIDER, FontProvider);
canvas.SetProperty(Property.FONT, FontProvider.GetFontSet());
var paragraph = new Paragraph(value) var paragraph = new Paragraph(value)
.SetFontSize(_pdfBurnerParams.FontSize) .SetFontSize(_pdfBurnerParams.FontSize)
.SetFontColor(ColorConstants.BLACK) .SetFontColor(ColorConstants.BLACK)
@@ -185,7 +199,8 @@ public class PDFBurner
paragraph.SetBold(); paragraph.SetBold();
} }
canvas.ShowTextAligned(paragraph, canvas.ShowTextAligned(
paragraph,
x + (float)_pdfBurnerParams.TopMargin, x + (float)_pdfBurnerParams.TopMargin,
y + (float)_pdfBurnerParams.YOffset, y + (float)_pdfBurnerParams.YOffset,
annotation.pageIndex + 1, annotation.pageIndex + 1,

View File

@@ -69,7 +69,7 @@ public class ReportCreator
private List<ReportItem> LoadReportItems(SqlConnection connection, int envelopeId) private List<ReportItem> LoadReportItems(SqlConnection connection, int envelopeId)
{ {
const string sql = "SELECT ENVELOPE_ID, HEAD_TITLE, HEAD_SUBJECT, POS_WHEN, POS_STATUS, POS_WHO FROM VWSIG_ENVELOPE_REPORT WHERE ENVELOPE_ID = @EnvelopeId"; const string sql = "SELECT ENVELOPE_ID, POS_WHEN, POS_STATUS, POS_WHO FROM VWSIG_ENVELOPE_REPORT WHERE ENVELOPE_ID = @EnvelopeId";
var result = new List<ReportItem>(); var result = new List<ReportItem>();
using var command = new SqlCommand(sql, connection); using var command = new SqlCommand(sql, connection);
@@ -80,11 +80,9 @@ public class ReportCreator
result.Add(new ReportItem result.Add(new ReportItem
{ {
EnvelopeId = reader.GetInt32(0), EnvelopeId = reader.GetInt32(0),
EnvelopeTitle = reader.IsDBNull(1) ? string.Empty : reader.GetString(1), ItemDate = reader.IsDBNull(1) ? DateTime.MinValue : reader.GetDateTime(1),
EnvelopeSubject = reader.IsDBNull(2) ? string.Empty : reader.GetString(2), ItemStatus = reader.IsDBNull(2) ? default : (EnvelopeGenerator.Domain.Constants.EnvelopeStatus)reader.GetInt32(2),
ItemDate = reader.IsDBNull(3) ? DateTime.MinValue : reader.GetDateTime(3), ItemUserReference = reader.IsDBNull(3) ? string.Empty : reader.GetString(3)
ItemStatus = reader.IsDBNull(4) ? default : (EnvelopeGenerator.Domain.Constants.EnvelopeStatus)reader.GetInt32(4),
ItemUserReference = reader.IsDBNull(5) ? string.Empty : reader.GetString(5)
}); });
} }