diff --git a/EnvelopeGenerator.Server/EnvelopeGenerator.Server/Program.cs b/EnvelopeGenerator.Server/EnvelopeGenerator.Server/Program.cs index 96ba37ca..fbdb824c 100644 --- a/EnvelopeGenerator.Server/EnvelopeGenerator.Server/Program.cs +++ b/EnvelopeGenerator.Server/EnvelopeGenerator.Server/Program.cs @@ -104,7 +104,7 @@ try { Version = "v1", Title = "signFLOW Absender-API", - Description = "Eine API zur Verwaltung der Erstellung, des Versands und der Nachverfolgung von Umschlägen in der signFLOW-Anwendung.", + Description = "Eine API zur Verwaltung der Erstellung, des Versands und der Nachverfolgung von Umschl�gen in der signFLOW-Anwendung.", Contact = new OpenApiContact { Name = "Digital Data GmbH", @@ -338,6 +338,10 @@ try builder.Services.AddDevExpressBlazor(); builder.Services.AddDevExpressServerSideBlazorPdfViewer(); + // PdfSharp font resolver — required for .NET 8 (no system font access without it) + PdfSharp.Fonts.GlobalFontSettings.FontResolver = + EnvelopeGenerator.Server.Services.PdfSharpFontResolver.Instance; + // Configuration Options builder.Services.Configure( builder.Configuration.GetSection("ApiOptions")); diff --git a/EnvelopeGenerator.Server/EnvelopeGenerator.Server/Services/PdfSharpFontResolver.cs b/EnvelopeGenerator.Server/EnvelopeGenerator.Server/Services/PdfSharpFontResolver.cs new file mode 100644 index 00000000..84acfe22 --- /dev/null +++ b/EnvelopeGenerator.Server/EnvelopeGenerator.Server/Services/PdfSharpFontResolver.cs @@ -0,0 +1,46 @@ +using PdfSharp.Fonts; + +namespace EnvelopeGenerator.Server.Services; + +/// +/// PdfSharp 6.x IFontResolver for .NET 8. +/// PdfSharp cannot access system fonts on .NET Core/8 without an explicit resolver. +/// This implementation reads fonts directly from the Windows Fonts folder. +/// Register once at startup: GlobalFontSettings.FontResolver = PdfSharpFontResolver.Instance; +/// +public class PdfSharpFontResolver : IFontResolver +{ + public static readonly PdfSharpFontResolver Instance = new(); + + private static readonly string FontsFolder = + Environment.GetFolderPath(Environment.SpecialFolder.Fonts); + + public FontResolverInfo? ResolveTypeface(string familyName, bool isBold, bool isItalic) + { + var key = familyName.ToLowerInvariant() switch + { + "arial" => isBold ? "arialbd" : "arial", + _ => null + }; + + return key is null ? null : new FontResolverInfo(key); + } + + public byte[] GetFont(string faceName) + { + var fileName = faceName switch + { + "arialbd" => "arialbd.ttf", + _ => "arial.ttf", + }; + + var path = Path.Combine(FontsFolder, fileName); + + if (!File.Exists(path)) + throw new FileNotFoundException( + $"Font file not found: {path}. " + + "Ensure Arial is installed on the server."); + + return File.ReadAllBytes(path); + } +}