PDFsharp & MigraDoc Forum

PDFsharp - A .NET library for processing PDF & MigraDoc - Creating documents on the fly
It is currently Sun Jun 22, 2025 6:03 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules

Also see our new Tailored Support & Services site.



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Thu May 15, 2025 7:13 am 
Offline

Joined: Thu Mar 31, 2022 8:49 am
Posts: 3
Hi all,

I am upgrading to PDFSharp-GDI 6.1 and would like to use custom font resolvers.

My app produces an in-app preview with the GDI functionality and then exports a PDF with the same content.

I'm using a custom font resolver, which works perfectly on the PDF export:

Code:
class Fontresolver : IFontResolver
{
   public byte[] GetFont(string faceName)
   {
      if (faceName == "Oswald")
         return File.ReadAllBytes(GlobalSettings.ResourceDirectory + "oswald-regular.ttf");
      else
         return null;
   }

   public FontResolverInfo ResolveTypeface(string familyName, bool isBold, bool isItalic)
   {
      if (familyName == "Oswald")
         return new("Oswald");
      return PlatformFontResolver.ResolveTypeface(familyName, isBold, isItalic);
   }
}


However, in the preview (drawing on a bitmap) I am seeing the following behavior: When Oswald is installed, the Oswald font is used for preview. When Oswald is not installed, I'm getting the error: "This font cannot be used by GDI+".

The documentation says:
Quote:
In the GDI and WPF builds, the selection of the requested typeface is delegated directly to GDI+ (System.Drawing) or WPF (System.Windows), respectively. This is the easiest case. The underlying Windows code selects the appropriate type face.

In the Core build of PDFsharp the concept of font resolvers is used.


If I understand correctly, this means that font resolvers cannot be used when drawing to a bitmap. Is that correct?


Top
 Profile  
Reply with quote  
PostPosted: Thu May 22, 2025 6:12 am 
Offline
PDFsharp Guru
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 1051
Location: CCAA
Hi!
Mithrandir wrote:
If I understand correctly, this means that font resolvers cannot be used when drawing to a bitmap. Is that correct?
That's correct.
PDFsharp used to have the XPrivateFontCollection class that also worked with bitmaps.
It no longer exists with 6.2.0.
I don't know how far you have to go back - try 6.1.1 or 6.0.0.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group