Welcome
Guest
•
Login
PDFsharp and MigraDoc Wiki
Navigation
¶
Main Page
Random Page
Create a new Page
All Pages
Categories
Navigation Paths
File Management
Create Account
Quick Search
»
Visit the new
Website for PDFsharp & MigraDoc Foundation 6.0 for .NET 6
and find information about the new version for Windows, Linux, and other platforms.
Back
PDFsharp Sample: Font Resolver
Modified on 2015/12/16 14:29
by
Thomas Hövel
Categorized as
MigraDoc Samples
,
PDFsharp Samples
,
Samples
{s:navigationPrevUpNext|ExportImages-sample|PDFsharpSamples|MultiplePages-sample} This sample shows how to use fonts that are included with your application. This allows you to use fonts that are not installed on the computer. For tasks running on web servers, private fonts may be the only available fonts. {s:note} When using the GDI build, you can use the XPrivateFontCollection class. As of PDFsharp 1.50 beta 2, the XPrivateFontCollection class is the recommended way for applications that use the GDI build of PDFsharp and that also use the screen preview or use the XGraphics class to draw on other contexts beside PDF files.{br} [PrivateFonts-sample|PDFsharp Sample: Private Fonts] The method shown in this sample works for the WPF build, the Core build, and the Silverlight build. This method has one drawback: it is not compatible with the DocumentPreview control that can be used with the WPF build. If your WPF application uses the DocumentPreview then stick to private fonts.{br} If you do not use the DocumentPreview, then use this method. It is the recommended method for applications running on web servers, it is the only method available for Silverlight applications. {s:note} The FontResolver is a global object and applies to all consumers of the PDFsharp library. It is also used when the MigraDoc library creates PDF files. ==The IFontResolver Interface== In your application you create a class that implements the IFontResolver interface (it is in the PdfSharp.Fonts namespace). There are only two methods you have to implement. The first method returns a FontResolverInfo for every supported font. {s:beginCsharp} public FontResolverInfo ResolveTypeface(string familyName, bool isBold, bool isItalic) {s:endCsharp} The other method is called using the FaceName from the FontResolverInfo you previously returned. At this stage, return the font data as a byte array. {s:beginCsharp} public byte[] GetFont(string faceName) {s:endCsharp} Now you only need one more step: register your font resolver using the global font resolver property. Here SegoeWpFontResolver is the class that implements IFontResolver. {s:beginCsharp} // Register font resolver before start using PDFsharp. GlobalFontSettings.FontResolver = new SegoeWpFontResolver(); {s:endCsharp} ==Additional Information== The font resolver set using GlobalFontSettings.FontResolver will be used by PDFsharp. Since MigraDoc uses PDFsharp to create PDF files, the font resolver will also be used when generating PDF files from MigraDoc. {s:sampleSourceCode}
Meta Keywords:
Meta Description:
Change Comment:
Visit the new
Website for PDFsharp & MigraDoc Foundation 6.0 for .NET 6
and find information about the new version for Windows, Linux, and other platforms.
Miscellaneous
Home
PDFsharp
FAQ
Samples
Articles
MigraDoc
FAQ
Samples
Articles
ScrewTurn Wiki version 3.0.5.600. Some of the icons created by
FamFamFam
.
Impressum - Privacy Policy, Data Protection Declaration, Legal Notice