Class PdfFont
Font info which describes the data structure of font referenced inside a PDF document.
Inheritance
Implements
Namespace: IronPdf.Fonts
Assembly: IronPdf.dll
Syntax
public class PdfFont : Object
PdfFont is the object IronPDF C# code works with for PDF fonts. It represents font info which describes the data structure of font referenced inside a PDF document.
PdfFont matters when an application needs to configure or invoke PDF fonts from C# code. The class encapsulates the related options and behavior in a single object that is set up once and reused across render or processing calls. Typical scenarios include batch generation pipelines, templated document workflows, and integration with existing C# document services.
To use PdfFont, instantiate or obtain it from the relevant entry point in the IronPDF C# API. Key properties include DescendantFontObjNum, DocumentId, FontData, FontSize. Assign options or invoke methods on the instance to configure or perform the operation.
using IronPdf;
// Obtain PdfFont from the relevant entry point in the IronPDF API
void Configure(PdfFont instance)
{
var current = instance.DescendantFontObjNum;
instance.Embed();
}For the broader workflow, see the IronPDF C# documentation for related how-to guides and examples. For broader context, the PDF fonts portion of the IronPDF C# API contains related types that work with PdfFont directly. PdfFont exposes additional members beyond those highlighted above; the reference tables on this page list the full set. In application code, treat PdfFont as a configured object that is constructed once and reused across operations rather than instantiated per call. Configuration is generally idempotent: assigning the same property value twice has the same effect as assigning it once. For diagnostic purposes, inspect the relevant PdfFont property after each operation to confirm the configured state. See the constructors, properties, and methods tables below for the complete API surface of PdfFont. Application code typically obtains or instantiates a single PdfFont and shares it across multiple IronPDF operations rather than recreating it per call.
Constructors
PdfFont(StandardFont)
Create a font object from standard font enumeration.
Declaration
public PdfFont(StandardFont font)
Parameters
| Type | Name | Description |
|---|---|---|
| StandardFont | font | StandardFont enumeration. If the standard font resolution fails, then System.ArgumentException is thrown. |
PdfFont(FontTypes)
Create a font object from IronSoftware.Drawing.FontTypes.
Declaration
public PdfFont(FontTypes font)
Parameters
| Type | Name | Description |
|---|---|---|
| IronSoftware.Drawing.FontTypes | font | IronSoftware.Drawing.FontTypes represents one of standard fonts of PDF document |
PdfFont(IPdfClient, IDocumentId, UInt32, Boolean, Boolean, String, FontType, UInt32)
Construct a FontInfo from all the specified arguments.
Declaration
public PdfFont(IPdfClient client, IDocumentId id, uint obj_num, bool is_embedded, bool is_subsetted, string name, FontType type, uint descendantFontObjNum = 0U)
Parameters
| Type | Name | Description |
|---|---|---|
| IronSoftware.Pdfium.IPdfClient | client | Pdf client |
| IronSoftware.Abstractions.Pdf.IDocumentId | id | Document identifier |
| System.UInt32 | obj_num | Object number representing the font object for use within PDF document |
| System.Boolean | is_embedded | True if this font is embedded, otherwise false. |
| System.Boolean | is_subsetted | |
| System.String | name | Name of the font |
| FontType | type | Type of the font. See FontType. |
| System.UInt32 | descendantFontObjNum | (Optional) Descendant object number. Default is 0. |
PdfFont(String)
Create a font object from a standard font string.
Declaration
public PdfFont(string StandardFont)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | StandardFont | One of 14 standard fonts which are guaranteed to be available and known within PDF document. If specified font cannot be resolved as one of the standard fonts, then System.ArgumentException is thrown. |
Properties
DescendantFontObjNum
Object number which represents a descendant font; a direct child font object from a composite font.
If its value is greater than 0, then the parent font is a composite font, and the value itself represent an actual descedant font (CIDFont) thus it can be either CIDFontType0, or CIDFontType2. Otherwise, value is 0 which means it is a simple font.
Declaration
public uint DescendantFontObjNum { get; }
Property Value
| Type | Description |
|---|---|
| System.UInt32 |
DocumentId
Declaration
public IDocumentId DocumentId { get; set; }
Property Value
| Type | Description |
|---|---|
| IronSoftware.Abstractions.Pdf.IDocumentId |
FontData
Declaration
public byte[] FontData { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Byte[] |
FontSize
Declaration
public float FontSize { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Single |
IsEmbedded
Declaration
public bool IsEmbedded { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
IsSubsetted
Declaration
public bool IsSubsetted { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
Name
Declaration
public string Name { get; set; }
Property Value
| Type | Description |
|---|---|
| System.String |
ObjNum
Declaration
public uint ObjNum { get; set; }
Property Value
| Type | Description |
|---|---|
| System.UInt32 |
PageIndex
Declaration
public uint PageIndex { get; set; }
Property Value
| Type | Description |
|---|---|
| System.UInt32 |
Type
Font type
Declaration
public FontType Type { get; }
Property Value
| Type | Description |
|---|---|
| FontType |
See Also
Methods
Embed(Byte[])
Embed all font file data for this font into the current document
Declaration
public void Embed(byte[] Data = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Byte[] | Data |
Exceptions
| Type | Condition |
|---|---|
| System.Exception | Font is not currently part of a document |
IsValidStandardFont(String)
Determines whether the specified font name is a valid standard font.
Declaration
public static bool IsValidStandardFont(string fontName)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | fontName | The name of the font to validate. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
ReplaceWith(Byte[])
Replace instances of this font with the specified custom font file
Declaration
public PdfFont ReplaceWith(byte[] FontData)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Byte[] | FontData | Custom font file data |
Returns
| Type | Description |
|---|---|
| PdfFont |
ReplaceWith(String)
Replace instances of this font with the specified standard font name
Declaration
public PdfFont ReplaceWith(string FontName)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | FontName | Standard font name |
Returns
| Type | Description |
|---|---|
| PdfFont |
ToString()
Return a string representation of this object.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| System.String | String representation of the object |
Unembed()
Unembed all font file data for this font from the current document
Declaration
public void Unembed()
Remarks
WARNING: Unembedding a font may cause text objects in the PDF that use this font to display incorrectly or not render at all. Ensure that unembedding is appropriate for the use case before proceeding.
Exceptions
| Type | Condition |
|---|---|
| System.Exception | Font is not currently part of a document |
Operators
Implicit(PdfFont to FontTypes)
Implicitly convert from PdfFont to IronSoftware.Drawing.FontTypes.
If internally it has invalid state prior to conversion, it will throw an exception System.InvalidOperationException.
Declaration
public static implicit operator FontTypes(PdfFont src)
Parameters
| Type | Name | Description |
|---|---|---|
| PdfFont | src |
Returns
| Type | Description |
|---|---|
| IronSoftware.Drawing.FontTypes |
Implicit(FontTypes to PdfFont)
Implicitly convert from IronSoftware.Drawing.FontTypes to PdfFont.
Declaration
public static implicit operator PdfFont(FontTypes src)
Parameters
| Type | Name | Description |
|---|---|---|
| IronSoftware.Drawing.FontTypes | src |
Returns
| Type | Description |
|---|---|
| PdfFont |