How to use unicode characters in MigraDoc in Linux

98 Views Asked by At

In latest Migradoc 6.0.0-preview-3, some unicode characters in PDF file appear as not accented in Linux. To to reproduce, run in Debian in ASP.NET MVC controller

  static ReportTemplateBase()
  {
    GlobalFontSettings.FontResolver = new NewFontResolver();
  }

  var textFrame = Section.AddTextFrame();
  var font = new Font("Arial", 12);
  var par = textFrame.AddParagraph();
  par.Format.Font = font;
  par.AddFormattedText("õäöüÕÄÖÜ", font);

If running in Debian Linux, äöü are replaced with unaccented characters. Output is

õaouÕAOU

If running from Visual Studio IDE in Windows, output is correct:

õäöüÕÄÖÜ

How to get correct characters in Debian Linux?

Looked into NewFontResolver source code in https://github.com/empira/PDFsharp/blob/91feca7521ad073cbfd132d4f957525824fbac17/src/foundation/src/shared/src/PdfSharp.Snippets/Font/fontresolving/NewFontResolver.cs#L186

It searches font files in Linux directories.

I copied .ttf files to /usr/share/fonts/fontsforpdfcreation directory and it looks like this solved the issue.

Is this OK?

1

There are 1 best solutions below

2
I liked the old Stack Overflow On BEST ANSWER

Create your own FontResolver implementing IFontResolver and include TTF files that have all the characters you need. Arial will do as it works under Windows.