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: Private Fonts
Modified on 2015/12/16 14:26
by
Thomas Hövel
Categorized as
PDFsharp Samples
,
Samples
,
TODO
{s:navigationPrevUpNext|Preview-sample|PDFsharpSamples|ProtectDocument-sample} This sample shows how to use fonts that are not installed with Windows. {s:note} XPrivateFontCollection is no longer supported and no longer recommended. This sample is outdated. Use the IFontResolver interface. Applications that use PDFsharp or MigraDoc 1.50 beta 3b or newer should use the IFontResolver interface.{br} [FontResolver-sample|PDFsharp Sample: Font Resolver] ==PDF Output File== See the PDF file created by this sample: {s:PdfLink|PrivateFonts-sample%2fPrivateFonts-output.pdf|output.pdf} (21 kB) ==Screen Shots== Here is a sample screen shot: {s:ImageThumbLink|PDF file with private fonts|PrivateFonts-sample%2fPrivateFontsth.png|PrivateFonts-sample%2fPrivateFonts.png} ==Source Code== This is the source code that shows how to load private fonts from a resource (WPF build): {s:beginCsharp} public void Add(Uri baseUri, string familyName) { if (String.IsNullOrEmpty(familyName)) throw new ArgumentNullException("familyName"); if (familyName.Contains(",")) throw new NotImplementedException("Only one family name is supported."); // family name starts right of '#' int idxHash = familyName.IndexOf('#'); if (idxHash < 0) throw new ArgumentException("Family name must contain a '#'. Example './#MyFontFamilyName'", "familyName"); string key = familyName.Substring(idxHash + 1); if (String.IsNullOrEmpty(key)) throw new ArgumentException("familyName has invalid format."); if (this.fontFamilies.ContainsKey(key)) throw new ArgumentException("An entry with the specified family name already exists."); System.Windows.Media.FontFamily fontFamily = new System.Windows.Media.FontFamily(baseUri, familyName); this.fontFamilies.Add(key, fontFamily); } {s:endCsharp} {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