I am trying to add text to a PDF document using private, i.e. not installed on the system, TrueType fonts and having trouble. I am using PDFSharp + MigraDoc WPF version 1.32.2608.0 from NuGet.
I have found numerous items on the forum and on StackOverFlow. The latest is this stackoverflow article which refers to this example on the PdfSharp site. However this example contains the code:
this.fontFamilies.Add(key, fontFamily);
on line 22, but I cannot find any reference to fontFamilies in assembly.
I therefore have followed what looked like an excellent example, but it does not work for me. When I use this approach I can successfully add the font but when I come to use the command:
var font = new XFont(fontStyle.Name, new XUnit(fontStyle.SizePt, XGraphicsUnit.Point), XFontStyle.Regular, _fontOptions);
Where fontStyle.Name
is the name of the font without the # on the front. At this point PdfSharp breaks inside the private void Initialise()
method inside the PdfSharp.Drawing namespace.
Inspecting the variables inside the Initialise
method at this point it has:
- Found the font family, i.e.
this.family != null
- Found the typeface, i.e.
this.typeface != null
I am assuming it break on the line if (!typeface2.TryGetGlyphTypeface(out typeface))
but I can't be sure.
Note: I have tried both a .ttf and a .otf font to no avail.
Could someone point me in the right direction please?
Update
In the end I swapped to PDFSharp WPF 1.50 beta as its font handling is MUCH better. See this SO post on my second issues and information on the new font resolver which solved my problem. Everything is working well now.