MigraDoc doesn't identify some installed TTF fonts

1.7k views Asked by At

I am using MigraDoc to create a PDF using the provided data to my method in C#. The PDF is getting generated just fine for most fonts but I have installed a new font on the system called "Dancing Script". This font is available on the system and I can use it with MS Word. I have also seen other entries similar to my query on SO but they don't solve my problem:

One example is this: MigraDoc: Setting font for a document

I am using the correct name, my font is installed and useable in Word. It is a TTF font. MigraDoc recognises the font as available in the system but when rendering the PDF it renders it like a san serif font.

The font I am using can be found here: http://www.impallari.com/dancing

My original code was this:

if (MigraDoc.DocumentObjectModel.Font.Exists(letter.fontName))
{
    paragraph.Format.Font = new MigraDoc.DocumentObjectModel.Font(letter.fontName);
}
else
{
    paragraph.Format.Font = new MigraDoc.DocumentObjectModel.Font("Arial");
}

I have also tried this:

Document document = new Document();
Section section = document.AddSection();
TextFrame tf;
Paragraph paragraph;

if (letter.fontName.ToLower().Equals("courier")) 
{
    letter.fontName = "Courier New";
}
MigraDoc.DocumentObjectModel.Style style = document.Styles["Normal"];
if (MigraDoc.DocumentObjectModel.Font.Exists(letter.fontName))
{
    style.Font.Name = letter.fontName;
    style.Font.Name = "Fineliner Script Regular";
}

But in both cases I am unable to get the font rendered on to the PDF. And I get the response:

---- DEBUG ASSERTION FAILED ----

---- Assert Short Message ---- Value differs from information retrieved from font image. ---- Assert Long Message ----

3

There are 3 answers

1
F Nadeem On BEST ANSWER

I managed to resolve the issue by simply rebooting my server. This is really weird becasue the font was working fine on Word Pad and other software but for some reason MigraDoc was unable to render it without a reboot. Hope this simply tip can help others who encounter the same issue.

3
I liked the old Stack Overflow On

I tried it with the name written like this style.Font.Name = "Dancing Script"; and MigraDoc used it correctly in the PDF.

You're not showing any code.

1
Tyeth On

The PDFsharp and Migradoc site (http://forum.pdfsharp.com/viewtopic.php?f=2&t=2265#p6534) list this error as an Assertion for DEBUG builds only, and will not be raised/show on RELEASE builds.

Technically the font spacing may be output incorrectly as that is what it's checking.

Sensible implementation but P-I-T-A for debugging, often IIS doesn't listen to me switching between debug and release, even disabling asp.net debugging in the project, equally have to reboot now and then.