Reputation: 132
I am currently working on a little piece of code which generates a PDF file. To follow the design specification, I need to use the 'Helvetica Neue Condensed Bold' font. As where the program will run, there is no font installation available I need to use it as a private font.
It does not work. I tried different family names and such, but I keep failing over and over...
byte[] data = File.ReadAllBytes(fontUri);
XPrivateFontCollection.Global.AddFont(data, "#Helvetica Neue Condensed Bold");
And when I want to use the font.
XFont big = new XFont("Helvetica Neue Condensed Bold", 36, XFontStyle.Regular);
But this keeps failing over and over again. I have imported the file into my project, it is a .ttf file. I cannot figure it out.
Is there anyone who knows my issue and maybe knows what I am doing wrong?
Upvotes: 2
Views: 4480
Reputation: 132
I have successfully solved the problem.
I was using the WPF Build instead of the GDI build. Besides that, the Uri's were wrong and the familynames were entered the wrong way.
Upvotes: 0
Reputation: 21739
When you download the PDFsharp source package, you will find a working sample that uses private fonts.
Use this to get started.
See folder "PDFSharp-MigraDocFoundation-1_32\PDFsharp\samples\Samples C#\Based on GDI+\PrivateFonts" after unzipping.
If you can't get it to work with your font, you will at least have an SSCCE which you can submit for testing.
Source code can be found here:
http://pdfsharp.codeplex.com/releases
Or maybe use PDFsharp 1.50 beta from NuGet where you use a FontResolver to work with private fonts.
See sample resolver here:
http://forum.pdfsharp.net/viewtopic.php?p=8961#p8961
Upvotes: 1