From 51920089af1a475cec6ecd3087972977e50943c4 Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Thu, 24 Apr 2025 16:08:05 +0200 Subject: [PATCH] =?UTF-8?q?feat(PDFBurner):=20PDFBurnerParams=20hinzuf?= =?UTF-8?q?=C3=BCgen=20und=20Konfiguration=20binden?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EnvelopeGenerator.BBTests/frmFinalizePDF.vb | 5 +++-- EnvelopeGenerator.Common/Constants.vb | 2 +- .../FinalizeDocument/FinalizeDocumentJob.vb | 4 ++-- .../Jobs/FinalizeDocument/PDFBurner.vb | 20 ++++++++----------- .../Jobs/PDFBurnerParams.vb | 2 +- EnvelopeGenerator.Service/Config.vb | 9 +++------ EnvelopeGenerator.Service/Scheduler.vb | 9 +++++---- EnvelopeGenerator.Service/Service.vb | 2 +- 8 files changed, 24 insertions(+), 29 deletions(-) diff --git a/EnvelopeGenerator.BBTests/frmFinalizePDF.vb b/EnvelopeGenerator.BBTests/frmFinalizePDF.vb index a0ef4043..d531f4e5 100644 --- a/EnvelopeGenerator.BBTests/frmFinalizePDF.vb +++ b/EnvelopeGenerator.BBTests/frmFinalizePDF.vb @@ -4,6 +4,7 @@ Imports GdPicture14 Imports Newtonsoft.Json.Linq Imports EnvelopeGenerator.Common.Jobs Imports System.IO +Imports EnvelopeGenerator.Common.Jobs.FinalizeDocument Public Class frmFinalizePDF Private Const CONNECTIONSTRING = "Server=sDD-VMP04-SQL17\DD_DEVELOP01;Database=DD_ECM;User Id=sa;Password=+bk8oAbbQP1AzoHtvZUbd+Mbok2f8Fl4miEx1qssJ5yEaEWoQJ9prg4L14fURpPnqi1WMNs9fE4=;" @@ -15,14 +16,14 @@ Public Class frmFinalizePDF Private Manager As AnnotationManager Private PDFBurner As FinalizeDocument.PDFBurner Private pGDPictureLicenseKey As String = "kG1Qf9PwmqgR8aDmIW2zI_ebj48RzqAJegRxcystEmkbTGQqfkNBdFOXIb6C_A00Ra8zZkrHdfjqzOPXK7kgkF2YDhvrqKfqh4WDug2vOt0qO31IommzkANSuLjZ4zmraoubyEVd25rE3veQ2h_j7tGIoH_LyIHmy24GaXsxdG0yCzIBMdiLbMMMDwcPY-809KeZ83Grv76OVhFvcbBWyYc251vou1N-kGg5_ZlHDgfWoY85gTLRxafjD3KS_i9ARW4BMiy36y8n7UP2jN8kGRnW_04ubpFtfjJqvtsrP_J9D0x7bqV8xtVtT5JI6dpKsVTiMgDCrIcoFSo5gCC1fw9oUopX4TDCkBQttO4-WHBlOeq9dG5Yb0otonVmJKaQA2tP6sMR-lZDs3ql_WI9t91yPWgpssrJUxSHDd27_LMTH_owJIqkF3NOJd9mYQuAv22oNKFYbH8e41pVKb8cT33Y9CgcQ_sy6YDA5PTuIRi67mjKge_nD9rd0IN213Ir9M_EFWqg9e4haWzIdHXQUo0md70kVhPX4UIH_BKJnxEEnFfoFRNMh77bB0N4jkcBEHPl-ghOERv8dOztf4vCnNpzzWvcLD2cqWIm6THy8XGGq9h4hp8aEreRleSMwv9QQAC7mjLwhQ1rBYkpUHlpTjhTLnMwHknl6HH0Z6zzmsgkRKVyfquv94Pd7QbQfZrRka0ss_48pf9p8hAywEn81Q==" - Private ReadOnly _ignoredLabels As New List(Of String) From {"Date", "Datum", "ZIP", "PLZ", "Place", "Ort", "Position", "Stellung"} + Private ReadOnly _pdfBurnerParams As New PDFBurnerParams() Private Sub frmFinalizePDF_Load(sender As Object, e As EventArgs) Handles MyBase.Load LogConfig = New LogConfig(LogConfig.PathType.CustomPath, Application.StartupPath) Database = New MSSQLServer(LogConfig, MSSQLServer.DecryptConnectionString(CONNECTIONSTRING)) - PDFBurner = New FinalizeDocument.PDFBurner(LogConfig, pGDPictureLicenseKey, _ignoredLabels) + PDFBurner = New FinalizeDocument.PDFBurner(LogConfig, pGDPictureLicenseKey, _pdfBurnerParams) Viewer = New GdViewer() Manager = New AnnotationManager() diff --git a/EnvelopeGenerator.Common/Constants.vb b/EnvelopeGenerator.Common/Constants.vb index 03e878cb..59570ee1 100644 --- a/EnvelopeGenerator.Common/Constants.vb +++ b/EnvelopeGenerator.Common/Constants.vb @@ -130,7 +130,7 @@ Public Const DATABASE = "DATABASE" Public Const LOGCONFIG = "LOGCONFIG" Public Const GDPICTURE = "GDPICTURE" - Public Const IGNORED_LABELS = "IgnoredLabels" + Public Const PDF_BURNER_PARAMS = "PDFBurnerParams" Public Const GREEN_300 = "#bbf7d0" Public Const RED_300 = "#fecaca" diff --git a/EnvelopeGenerator.Common/Jobs/FinalizeDocument/FinalizeDocumentJob.vb b/EnvelopeGenerator.Common/Jobs/FinalizeDocument/FinalizeDocumentJob.vb index a0b33b78..94ac0d34 100644 --- a/EnvelopeGenerator.Common/Jobs/FinalizeDocument/FinalizeDocumentJob.vb +++ b/EnvelopeGenerator.Common/Jobs/FinalizeDocument/FinalizeDocumentJob.vb @@ -74,8 +74,8 @@ Namespace Jobs InitializeServices(oState) Logger.Debug("Loading PDFBurner..") - Dim ignoredLabels As List(Of String) = pContext.MergedJobDataMap.Item(Constants.IGNORED_LABELS) - PDFBurner = New PDFBurner(LogConfig, oGdPictureKey, ignoredLabels) + Dim pdfBurnerParams As PDFBurnerParams = pContext.MergedJobDataMap.Item(Constants.PDF_BURNER_PARAMS) + PDFBurner = New PDFBurner(LogConfig, oGdPictureKey, pdfBurnerParams) Logger.Debug("Loading PDFMerger..") PDFMerger = New PDFMerger(LogConfig, oGdPictureKey) diff --git a/EnvelopeGenerator.Common/Jobs/FinalizeDocument/PDFBurner.vb b/EnvelopeGenerator.Common/Jobs/FinalizeDocument/PDFBurner.vb index c6b61c78..b69d2b12 100644 --- a/EnvelopeGenerator.Common/Jobs/FinalizeDocument/PDFBurner.vb +++ b/EnvelopeGenerator.Common/Jobs/FinalizeDocument/PDFBurner.vb @@ -16,9 +16,9 @@ Namespace Jobs.FinalizeDocument Private Const ANNOTATION_TYPE_IMAGE = "pspdfkit/image" Private Const ANNOTATION_TYPE_INK = "pspdfkit/ink" Private Const ANNOTATION_TYPE_WIDGET = "pspdfkit/widget" - Private Property _ignoredLabels As List(Of String) + Private Property _pdfBurnerParams As PDFBurnerParams - Public Sub New(pLogConfig As LogConfig, pGDPictureLicenseKey As String, ignoredLabels As List(Of String)) + Public Sub New(pLogConfig As LogConfig, pGDPictureLicenseKey As String, pdfBurnerParams As PDFBurnerParams) MyBase.New(pLogConfig) LicenseManager = New LicenseManager() @@ -26,7 +26,7 @@ Namespace Jobs.FinalizeDocument Manager = New AnnotationManager() - _ignoredLabels = ignoredLabels + _pdfBurnerParams = pdfBurnerParams End Sub Public Function BurnInstantJSONAnnotationsToPDF(pSourceBuffer As Byte(), pInstantJSONList As List(Of String)) As Byte() @@ -82,7 +82,7 @@ Namespace Jobs.FinalizeDocument Case ANNOTATION_TYPE_WIDGET 'Add form field values Dim formFieldValue = oAnnotationData.formFieldValues.FirstOrDefault(Function(fv) fv.name = oAnnotation.id) - If formFieldValue IsNot Nothing AndAlso Not _ignoredLabels.Contains(formFieldValue.value) Then + If formFieldValue IsNot Nothing AndAlso Not _pdfBurnerParams.IgnoredLabels.Contains(formFieldValue.value) Then AddFormFieldValue(oAnnotation, formFieldValue, formFieldIndex) formFieldIndex += 1 End If @@ -152,12 +152,8 @@ Namespace Jobs.FinalizeDocument ' Convert pixels to Inches Dim oBounds = pAnnotation.bbox.Select(AddressOf ToInches).ToList() - Dim top_margin = 0.1 - - Dim y_offset = -0.3 - Dim oX = oBounds.Item(0) - Dim oY = oBounds.Item(1) + y_offset * index + top_margin + Dim oY = oBounds.Item(1) + _pdfBurnerParams.YOffset * index + _pdfBurnerParams.TopMargin Dim oWidth = oBounds.Item(2) Dim oHeight = oBounds.Item(3) @@ -166,9 +162,9 @@ Namespace Jobs.FinalizeDocument Dim ant = Manager.AddTextAnnot(oX, oY, oWidth, oHeight, formFieldValue.value) ' Set the font properties - ant.FontName = "Arial" - ant.FontSize = 8 - ant.FontStyle = FontStyle.Italic + ant.FontName = _pdfBurnerParams.FontName + ant.FontSize = _pdfBurnerParams.FontSize + ant.FontStyle = _pdfBurnerParams.FontStyle Manager.SaveAnnotationsToPage() Return True Catch ex As Exception diff --git a/EnvelopeGenerator.Common/Jobs/PDFBurnerParams.vb b/EnvelopeGenerator.Common/Jobs/PDFBurnerParams.vb index 954f6cb7..019db1fb 100644 --- a/EnvelopeGenerator.Common/Jobs/PDFBurnerParams.vb +++ b/EnvelopeGenerator.Common/Jobs/PDFBurnerParams.vb @@ -1,7 +1,7 @@ Imports System.Drawing Namespace Jobs.FinalizeDocument Public Class PDFBurnerParams - Public Property _ignoredLabels As List(Of String) + Public Property IgnoredLabels As New List(Of String) From {"Date", "Datum", "ZIP", "PLZ", "Place", "Ort", "Position", "Stellung"} Public Property TopMargin As Double = 0.1 diff --git a/EnvelopeGenerator.Service/Config.vb b/EnvelopeGenerator.Service/Config.vb index 2e04fd0a..fd572b5e 100644 --- a/EnvelopeGenerator.Service/Config.vb +++ b/EnvelopeGenerator.Service/Config.vb @@ -1,16 +1,13 @@ Imports DigitalData.Modules.Config.ConfigAttributes +Imports EnvelopeGenerator.Common.Jobs.FinalizeDocument Public Class Config Public Property ConnectionString As String = "" Public Property Debug As Boolean = False + Public Property IntervalInMin As Integer = 1 - Public Property IgnoredLabels As List(Of String) = New List(Of String) From { - "Date", "Datum", - "ZIP", "PLZ", - "Place", "Ort", - "Position", "Stellung" - } + Public Property PDFBurnerParams As PDFBurnerParams = New PDFBurnerParams() End Class diff --git a/EnvelopeGenerator.Service/Scheduler.vb b/EnvelopeGenerator.Service/Scheduler.vb index a6cf19ad..1362e355 100644 --- a/EnvelopeGenerator.Service/Scheduler.vb +++ b/EnvelopeGenerator.Service/Scheduler.vb @@ -3,6 +3,7 @@ Imports DigitalData.Modules.Base Imports DigitalData.Modules.Database Imports DigitalData.Modules.Logging Imports EnvelopeGenerator.Common.Jobs +Imports EnvelopeGenerator.Common.Jobs.FinalizeDocument Imports Quartz Public Class Scheduler @@ -11,15 +12,15 @@ Public Class Scheduler Private Scheduler As IScheduler Private ReadOnly ConnectionString As String Private ReadOnly LicenseKey As String - Private Property _ignoredLabels As List(Of String) + Private Property _pdfBurnerParams As PDFBurnerParams Private Const JobName = "CertificateDocumentJob" - Public Sub New(pLogConfig As LogConfig, pConnectionString As String, pLicenseKey As String, ignoredLabels As List(Of String)) + Public Sub New(pLogConfig As LogConfig, pConnectionString As String, pLicenseKey As String, pdfBurnerParams As PDFBurnerParams) MyBase.New(pLogConfig) ConnectionString = pConnectionString LicenseKey = pLicenseKey - _ignoredLabels = ignoredLabels + _pdfBurnerParams = pdfBurnerParams Dim oLogProvider = New LogProvider(Logger) Logging.LogProvider.SetCurrentLogProvider(oLogProvider) @@ -40,7 +41,7 @@ Public Class Scheduler {Common.Constants.GDPICTURE, LicenseKey}, {Common.Constants.LOGCONFIG, LogConfig}, {Common.Constants.DATABASE, ConnectionString}, - {Common.Constants.IGNORED_LABELS, _ignoredLabels} + {Common.Constants.PDF_BURNER_PARAMS, _pdfBurnerParams} } Logger.Debug("Initialized Job [{0}]", JobName) diff --git a/EnvelopeGenerator.Service/Service.vb b/EnvelopeGenerator.Service/Service.vb index c5424899..c0e1a88b 100644 --- a/EnvelopeGenerator.Service/Service.vb +++ b/EnvelopeGenerator.Service/Service.vb @@ -55,7 +55,7 @@ Public Class Service Logger.Debug("Inititalize Quartz") - Scheduler = New Scheduler(LogConfig, Config.ConnectionString, oKey, Config.IgnoredLabels) + Scheduler = New Scheduler(LogConfig, Config.ConnectionString, oKey, Config.PDFBurnerParams) Await Scheduler.Start(Config.IntervalInMin) Logger.Info("Started [{0}] !", ServiceName)