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:
@@ -7,6 +7,8 @@ using iText.Kernel.Pdf;
|
||||
using iText.Kernel.Pdf.Canvas;
|
||||
using iText.Layout;
|
||||
using iText.Layout.Element;
|
||||
using iText.Layout.Font;
|
||||
using iText.Layout.Properties;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using Newtonsoft.Json;
|
||||
@@ -17,6 +19,7 @@ namespace EnvelopeGenerator.Jobs.FinalizeDocument;
|
||||
|
||||
public class PDFBurner
|
||||
{
|
||||
private static readonly FontProvider FontProvider = CreateFontProvider();
|
||||
private readonly ILogger<PDFBurner> _logger;
|
||||
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)
|
||||
{
|
||||
var bounds = annotation.bbox.Select(ToInches).ToList();
|
||||
@@ -170,6 +181,9 @@ public class PDFBurner
|
||||
|
||||
var page = pdf.GetPage(annotation.pageIndex + 1);
|
||||
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)
|
||||
.SetFontSize(_pdfBurnerParams.FontSize)
|
||||
.SetFontColor(ColorConstants.BLACK)
|
||||
@@ -185,7 +199,8 @@ public class PDFBurner
|
||||
paragraph.SetBold();
|
||||
}
|
||||
|
||||
canvas.ShowTextAligned(paragraph,
|
||||
canvas.ShowTextAligned(
|
||||
paragraph,
|
||||
x + (float)_pdfBurnerParams.TopMargin,
|
||||
y + (float)_pdfBurnerParams.YOffset,
|
||||
annotation.pageIndex + 1,
|
||||
|
||||
@@ -69,7 +69,7 @@ public class ReportCreator
|
||||
|
||||
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>();
|
||||
|
||||
using var command = new SqlCommand(sql, connection);
|
||||
@@ -80,11 +80,9 @@ public class ReportCreator
|
||||
result.Add(new ReportItem
|
||||
{
|
||||
EnvelopeId = reader.GetInt32(0),
|
||||
EnvelopeTitle = reader.IsDBNull(1) ? string.Empty : reader.GetString(1),
|
||||
EnvelopeSubject = reader.IsDBNull(2) ? string.Empty : reader.GetString(2),
|
||||
ItemDate = reader.IsDBNull(3) ? DateTime.MinValue : reader.GetDateTime(3),
|
||||
ItemStatus = reader.IsDBNull(4) ? default : (EnvelopeGenerator.Domain.Constants.EnvelopeStatus)reader.GetInt32(4),
|
||||
ItemUserReference = reader.IsDBNull(5) ? string.Empty : reader.GetString(5)
|
||||
ItemDate = reader.IsDBNull(1) ? DateTime.MinValue : reader.GetDateTime(1),
|
||||
ItemStatus = reader.IsDBNull(2) ? default : (EnvelopeGenerator.Domain.Constants.EnvelopeStatus)reader.GetInt32(2),
|
||||
ItemUserReference = reader.IsDBNull(3) ? string.Empty : reader.GetString(3)
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user