Fehlerbehandlung & PDF-Stabilität verbessert

In `MSSQLServer.vb` wurde die Fehlerbehandlung erweitert, indem Fehler beim Öffnen einer Verbindung (`pConnection.Open`) nun protokolliert werden.
Die Versionsinformationen in `AssemblyInfo.vb` wurden von `3.8.1.0` auf `3.8.2.0` aktualisiert.
In `XRechnungViewDocument.vb` wurde die Methode `RenderLabelValuePair` angepasst, um Eingabewerte mit der neuen Methode `SanitizeForPdf` zu bereinigen. Diese entfernt problematische Unicode-Zeichen, die Abstürze beim PDF-Rendering verursachen könnten, und protokolliert entfernte Zeichen. Dies erhöht die Stabilität und Sicherheit.
This commit is contained in:
Developer01
2026-09-17 12:35:36 +02:00
parent 3c1b51f519
commit d3ebc13eae
3 changed files with 45 additions and 6 deletions

View File

@@ -255,6 +255,7 @@ Public Class MSSQLServer
Return pConnection
Catch ex As Exception
Logger.Error("Error while opening Connection!")
Logger.Error(ex)

View File

@@ -13,7 +13,7 @@ Imports System.Runtime.InteropServices
<Assembly: AssemblyCompany("Digital Data")>
<Assembly: AssemblyProduct("Modules.Jobs")>
<Assembly: AssemblyCopyright("Copyright © 2026")>
<Assembly: AssemblyTrademark("3.8.1.0")>
<Assembly: AssemblyTrademark("3.8.2.0")>
<Assembly: ComVisible(False)>
@@ -30,5 +30,5 @@ Imports System.Runtime.InteropServices
' Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
' übernehmen, indem Sie "*" eingeben:
<Assembly: AssemblyVersion("3.8.1.0")>
<Assembly: AssemblyFileVersion("3.8.1.0")>
<Assembly: AssemblyVersion("3.8.2.0")>
<Assembly: AssemblyFileVersion("3.8.2.0")>

View File

@@ -895,17 +895,55 @@ Public Class XRechnungViewDocument
End Function
Private Sub RenderLabelValuePair(context As PdfRenderContext, label As String, value As String)
context.PDF.DrawText(fontResName, MARGIN_LEFT, context.YPosition, label)
Dim safeLabel As String = SanitizeForPdf(label)
Dim safeValue As String = SanitizeForPdf(value)
context.PDF.DrawText(fontResName, MARGIN_LEFT, context.YPosition, safeLabel)
If context.CreateTextBox Then
Dim textBoxYPos As Integer = context.YPosition - 3
context.PDF.DrawTextBox(fontResName, COL_VALUE_X, textBoxYPos, 90, YCoo_TextBoxPlus5(textBoxYPos),
TextAlignment.TextAlignmentFar, TextAlignment.TextAlignmentCenter,
value)
safeValue)
Else
context.PDF.DrawText(fontResName, COL_VALUE_X, context.YPosition, value)
context.PDF.DrawText(fontResName, COL_VALUE_X, context.YPosition, safeValue)
End If
End Sub
''' <summary>
''' Bereinigt einen String vor der Übergabe an GdPicture DrawText.
''' Entfernt Steuerzeichen, Surrogate und Format-/BiDi-Zeichen,
''' die GdPictures UnicodeBidi-Algorithmus zum Absturz bringen.
''' </summary>
Private Function SanitizeForPdf(text As String) As String
If String.IsNullOrEmpty(text) Then Return String.Empty
Dim sb As New System.Text.StringBuilder(text.Length)
Dim removedChars As New System.Text.StringBuilder()
For Each c As Char In text
Dim cat As Globalization.UnicodeCategory = Char.GetUnicodeCategory(c)
Dim isProblematic As Boolean =
cat = Globalization.UnicodeCategory.Control OrElse
cat = Globalization.UnicodeCategory.Surrogate OrElse
cat = Globalization.UnicodeCategory.Format OrElse
cat = Globalization.UnicodeCategory.OtherNotAssigned OrElse
Char.IsHighSurrogate(c) OrElse
Char.IsLowSurrogate(c)
If isProblematic Then
removedChars.Append($"U+{AscW(c):X4}[{cat}] ")
Else
sb.Append(c)
End If
Next
If removedChars.Length > 0 Then
_logger.Warn($"SanitizeForPdf: Removed [{removedChars.ToString().Trim()}] from text [{text.Substring(0, Math.Min(80, text.Length))}]")
End If
Return sb.ToString()
End Function
Private Sub RenderTextWithWrapping(context As PdfRenderContext, text As String)
If text.Length > MAX_TEXT_LENGTH_FULL Then