MigraDoc settings
Version 6.1.0
In this article
This article describes which MigraDoc-wide settings can be configured and how it’s done.
Font resolving
All fonts of your document must be resolvable. This includes all fonts you set at document objects or styles, the error font, and the bullet fonts when using bullet lists (see Predefined fonts and bullet chars).
If you want to create a PDF file from a MigraDoc document, we recommend to use a custom font resolver which supports all the required fonts (see Font resolving for more information). When using the GDI or WPF build of MigraDoc (see Choose a PDFsharp build for more information) or when using the Core build under Windows only, you are not forced to implement and use an own font resolver (see Font resolving for alternatives) - but we still highly recommend to do so in production environments.
If you only want to create an RTF file, this step is not needed as fonts are not embedded in RTF files.
As the font resolver should be set on program start, you can find the code setting the font resolver for the MigraDoc Document Object Model samples in the Program class:
#if CORE
// Core build does not use Windows fonts,
// so set a FontResolver that handles the fonts our samples need.
GlobalFontSettings.FontResolver = new SamplesFontResolver();
#endif
See full Program.cs file in PDFsharp.Sample repository.
Of course, you can use the SamplesFontResolver as a reference to implement your own font resolver (see Sample resolvers). But pay attention that SamplesFontResolver loads the fonts from the repository-specific assets folder of PDFsharp.Samples, while you must provide your font files in an appropriate way that works without repository.
See also:
Font resolving for information about PDFsharp font resolvers
Predefined fonts and bullet chars
There is a set of predefined fonts and bullet chars you can change globally at the static PredefinedFontsAndChars class.
Error font
There is a predefined font used to write error messages to your document if, for example, an image could not be loaded. By default, Courier New is used as an error font. You can set your own error font like this:
// Set the error font.
PredefinedFontsAndChars.ErrorFontName = "Arial";
See full PredefinedFonts sample in PDFsharp.Sample repository. Show resulting PDF
The error font must always be resolvable (see Font resolving), so your font resolver must include the font set in ErrorFontName. The default value of the property is Courier New.
Bullet fonts and chars
For each of MigraDoc’s bullet list levels you can configure the font and the char to use as the bullet:
// Set the bullet font and char for list level 1.
PredefinedFontsAndChars.Bullets.Level1FontName = "Wingdings";
PredefinedFontsAndChars.Bullets.Level1Character = '\u0076';
// Set the bullet font and char for list level 2.
PredefinedFontsAndChars.Bullets.Level2FontName = "Wingdings";
PredefinedFontsAndChars.Bullets.Level2Character = '\u00AA';
// Set the bullet font and char for list level 3.
PredefinedFontsAndChars.Bullets.Level3FontName = "Wingdings";
PredefinedFontsAndChars.Bullets.Level3Character = '\u0077';
See full PredefinedFonts sample in PDFsharp.Sample repository. Show resulting PDF
For bullet lists, the actual font face depends on the context, as Bold and Italic values may influence font resolving. Therefore, the needed fonts are only tried to be resolved when the document contains a bullet list that uses them. Only in that case the font resolver must support the needed fonts. By default, Courier New with the characters '●', '○' and '▪' is used. In Courier New they look slightly different (see Bulleted lists sample in Contents / Lists.