2
votes

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?

2
Do you have some exception thrown? - activatedgeek
@activatedgeek: I do not get any exceptions. - Martin Beentjes
@SamY: Can't use that, working with PdfSharp.. The XGraphics.DrawString method expects an XFont and not a Font. - Martin Beentjes
@SamY: As said in the post, it is not possible to install fonts on the server (they do not want to do that). - Martin Beentjes

2 Answers

1
votes

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

0
votes

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.