Using Private Fonts
Modified on 2015/12/16 14:23 by Thomas Hövel — Categorized as: Articles, MigraDoc Articles, PDFsharp Articles
What are "Private Fonts"?
¶
Private fonts refers to fonts that ship with your application, fonts that are not installed (or do not have to be installed) on the computer that executes your application.
When do I use "Private Fonts"?
¶
You use private fonts when you cannot or don't want to install those fonts on that computer. Or when your application has insufficient privileges to read the fonts from the system.
For applications running on web servers, it may be impossible to install the fonts on the server due to limited rights. Or your application may have insufficient rights to access the font files on the computer.
Administrator privileges are needed to install fonts on a computer. If you use private fonts, your application can be installed and used even without administrator privileges (e.g. using XCopy deployment) and your application can still use the fonts you include in your assembly or your folder.
How do I use "Private Fonts"?
¶
Currently there are two methods, but not all platforms support both methods.
IFontResolver
¶
IFontResolver is new with PDFsharp 1.50.
It cannot be used with the GDI build of PDFsharp.
It cannot be used with the WPF build of PDFsharp if you want to use the DocumentPreview - fonts used with IFontResolver are not available in the preview.
For all other platforms (Silverlight, Windows Phone) this is the method of choice.
XPrivateFontCollection
¶
XPrivateFontCollection is no longer supported and not recommended (as of PDFsharp 1.50 beta 3b).
It should work with GDI and WPF builds.
FontFamily
¶
The class System.Windows.Media.FontFamily is part of WPF, therefore this method can only be used with the WPF build.
Sample Code
¶
PDFsharp Sample: Font Resolver
shows how to use IFontResolver. This method can be used with any build of PDFsharp 1.50 and later except for the GDI build.
Using "Private Fonts" with MigraDoc
¶
MigraDoc uses PDFsharp to create PDF files. You have to register your private fonts with PDFsharp and MigraDoc will use them when creating PDF files.
MigraDoc will not embed private fonts when creating RTF files.