Closed chris-steema closed 1 year ago
The font can be loaded using the IFontResolver interface. Tested with EZFontResolver. http://developer.th-soft.com/developer/2015/12/11/ezfontresolver-a-generic-font-resolver-for-pdfsharp-and-migradoc/
In your code you are using these two lines where the error occurs:
var font0 = new Font(privateFonts.Families[0], 20, FontStyle.Bold);
XFont font = new XFont(font0, new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Default));
The error does not occur when you skip the Font object and create the XFont object directly:
XFont font = new XFont((FontFamily)privateFonts.Families[0], 20, XFontStyle.Bold);
The XFontOptions can also be specified here:
XFont font = new XFont((FontFamily)privateFonts.Families[0], 20, XFontStyle.Bold, new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Default));
This is by design: Creating an XFont
from Font
works only when the font uses world co-ordinates.
Creating the XFont
directly from the font name is an easy solution for installed fonts.
Implementing IFontResolver
is another option.
Expected Behavior
I've modified the PdfSharpIssueSurrogate on a fork on my account here. This uses the Jiyu No Tsubasa font, which is a TrueType font (JiyunoTsubasa.ttf). As per the PDFsharp documentation here, I would expect this font to be used correctly.
Actual Behavior
The code throws the following error:
And this error is thrown whichever values I choose for PdfFontEncoding and PdfFontEmbedding.
Steps to Reproduce the Behavior
Please use the code above as specified.