Click or drag to resize
Pdf Library for .NET

PdfFontCollection Class

Collection of fonts associated with a PdfDocument. Accessed through Fonts.
Inheritance Hierarchy
SystemObject
  SelectPdf.UniversalPdfFontCollection

Namespace: SelectPdf.Universal
Assembly: SelectPdf.HtmlToPdf.Universal (in SelectPdf.HtmlToPdf.Universal.dll) Version: 26.4
Syntax
public class PdfFontCollection : IEnumerable<PdfFont>, 
	IEnumerable

The PdfFontCollection type exposes the following members.

Properties
 NameDescription
Public propertyCountGets the number of fonts in the collection.
Public propertyDocumentGets the parent PDF document.
Public propertyItemGets the font at the specified zero-based index.
Top
Methods
 NameDescription
Public methodAdd(Byte) Adds a TrueType / OpenType font loaded from an in-memory byte array. Convenience overload that avoids needing a temporary file.
Public methodAdd(PdfFont) Adds an already-constructed PdfFont to the collection. Useful when you want to track a font that was created with an explicit size via CreateStandardFont(PdfStandardFont, Single) etc.
Public methodAdd(PdfFont)Adds an array of fonts to the collection.
Public methodAdd(PdfStandardCJKFont) Adds a standard CJK font to the collection. Like PdfStandardFont, these are referenced by name (not embedded) — but CJK readers ship the glyphs, so output is expected to render on PDF/A-capable viewers.
Public methodAdd(PdfStandardFont) Adds a standard PDF font (one of the 14 built-in font names) to the collection and returns the PdfFont wrapper. Standard fonts are referenced by name, not embedded — rejected under PDF/A and PDF/X conformance.
Public methodAdd(PdfSystemFont) Resolves the system font described by systemFont to its installed TrueType / OpenType file, subset-embeds it into the document, and returns the resulting PdfFont.
Public methodAdd(Stream) Adds a TrueType / OpenType font loaded from a Stream. The stream is read synchronously from its current position to end.
Public methodAdd(String) Adds a TrueType / OpenType font loaded from a file. The font is subset-embedded into the output document — use this path for PDF/A / PDF/X output from scratch.
Public methodAdd(PdfSystemFont, Boolean) Resolves the system font described by systemFont and adds it to the collection.
Public methodContainsReturns true if the specified font is in the collection.
Public methodGetEnumeratorReturns an enumerator over the fonts in insertion order.
Public methodIndexOfReturns the zero-based index of the specified font, or -1 if not found.
Public methodInsertInserts a font at the specified zero-based index.
Public methodRemoveRemoves the specified font from the collection.
Top
Remarks
Adding a font returns a PdfFont that can be retained and reused with any PdfTextElement on the document. Adding the exact same font twice returns two distinct registry entries — duplicate detection is left to the caller.
Example
PdfDocument document = new PdfDocument();
PdfFont helvetica = document.Fonts.Add(PdfStandardFont.Helvetica);
PdfFont arial = document.Fonts.Add(@"C:\Windows\Fonts\arial.ttf");
int count = document.Fonts.Count;
See Also