Search code examples
c#migradoc

Trouble displaying Circle plus (⊕) in PDF generated using MigraDoc


When generating a PDF, the ⊕ symbol is not displayed, but the replacement symbol is displayed instead of it. Is it possible to work around this problem somehow?

Versions tested:

  • 1.32
  • 1.5 beta 3

Fonts tested:

  • Arial
  • Verdana
  • Lucida Console
  • Consolas

Code

string fileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".pdf");
var doc = new Document();
doc.Styles["Normal"].Font.Name = "Consolas";

doc.AddSection().AddParagraph("A ⊕ B");

var pdfRenderer = new PdfDocumentRenderer(true);
pdfRenderer.Document = doc;
pdfRenderer.RenderDocument();
pdfRenderer.PdfDocument.Save(fileName);

Process.Start(fileName);

Solution

  • Use a font that contains the character "Circled Plus".

    You can use e.g. "Segoe UI Symbol". "Segoe UI" does not contain that character.

    MS Word switches the fonts automatically when such symbols are used, with MigraDoc you have to switch the font as needed.

    If you want to use "Consolas" for the rest of the text, use AddFormattedText for the Circled Plus and switch to e.g. "Segoe UI Symbol" for this symbol.