diff --git a/Database/Adapters/MSSQLServer.vb b/Database/Adapters/MSSQLServer.vb index 05ce1897..3d218362 100644 --- a/Database/Adapters/MSSQLServer.vb +++ b/Database/Adapters/MSSQLServer.vb @@ -255,6 +255,7 @@ Public Class MSSQLServer Return pConnection Catch ex As Exception + Logger.Error("Error while opening Connection!") Logger.Error(ex) diff --git a/Jobs/My Project/AssemblyInfo.vb b/Jobs/My Project/AssemblyInfo.vb index 4db508fe..7053521d 100644 --- a/Jobs/My Project/AssemblyInfo.vb +++ b/Jobs/My Project/AssemblyInfo.vb @@ -13,7 +13,7 @@ Imports System.Runtime.InteropServices - + @@ -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: - - + + diff --git a/Jobs/ZUGFeRD/XRechnungViewDocument.vb b/Jobs/ZUGFeRD/XRechnungViewDocument.vb index 6292f59e..ef1c2edf 100644 --- a/Jobs/ZUGFeRD/XRechnungViewDocument.vb +++ b/Jobs/ZUGFeRD/XRechnungViewDocument.vb @@ -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 + ''' + ''' Bereinigt einen String vor der Übergabe an GdPicture DrawText. + ''' Entfernt Steuerzeichen, Surrogate und Format-/BiDi-Zeichen, + ''' die GdPictures UnicodeBidi-Algorithmus zum Absturz bringen. + ''' + 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