# Font Class

> Represents a font.

- Product: Adobe PDF Library 18
- Language: .NET
- Version: APDFL18.0.5PlusP2e
- HTML page: https://docs.datalogics.com/apdfl18/DotNet/APDFL18.0.5PlusP2e/class/Font
- Version index: https://docs.datalogics.com/apdfl18/DotNet/APDFL18.0.5PlusP2e/llms.txt

```csharp
class Font : SystemIDisposable
```

**Namespace:** `Datalogics::PDFL`

**Inherits from:** `SystemIDisposable`

## Description

Represents a font. Defines the typeface, size, style (bold, italic), Unicode values, and other details.

The Font class represents a font installed on the system.

**Referenced by:** [`Document`](https://docs.datalogics.com/apdfl18/DotNet/APDFL18.0.5PlusP2e/class/Document.md), [`Font`](https://docs.datalogics.com/apdfl18/DotNet/APDFL18.0.5PlusP2e/class/Font.md), [`Redaction`](https://docs.datalogics.com/apdfl18/DotNet/APDFL18.0.5PlusP2e/class/Redaction.md), [`Text`](https://docs.datalogics.com/apdfl18/DotNet/APDFL18.0.5PlusP2e/class/Text.md), [`TextRun`](https://docs.datalogics.com/apdfl18/DotNet/APDFL18.0.5PlusP2e/class/TextRun.md), [`WatermarkTextParams`](https://docs.datalogics.com/apdfl18/DotNet/APDFL18.0.5PlusP2e/class/WatermarkTextParams.md)

**Uses types:** [`Document`](https://docs.datalogics.com/apdfl18/DotNet/APDFL18.0.5PlusP2e/class/Document.md), [`EncodingInfo`](https://docs.datalogics.com/apdfl18/DotNet/APDFL18.0.5PlusP2e/class/EncodingInfo.md), [`Font`](https://docs.datalogics.com/apdfl18/DotNet/APDFL18.0.5PlusP2e/class/Font.md), [`FontCreateFlags`](https://docs.datalogics.com/apdfl18/DotNet/APDFL18.0.5PlusP2e/enum/FontCreateFlags.md), [`FontFlags`](https://docs.datalogics.com/apdfl18/DotNet/APDFL18.0.5PlusP2e/enum/FontFlags.md), [`PDFDict`](https://docs.datalogics.com/apdfl18/DotNet/APDFL18.0.5PlusP2e/class/PDFDict.md), [`Rect`](https://docs.datalogics.com/apdfl18/DotNet/APDFL18.0.5PlusP2e/class/Rect.md), [`WritingMode`](https://docs.datalogics.com/apdfl18/DotNet/APDFL18.0.5PlusP2e/enum/WritingMode.md)

## Constructors

### Font

```csharp
Datalogics.PDFL.Font.Font(string fontName)
```

*constructor*

**Parameters**

- `fontName` (`string`): the name of the font to find and create

Find a font with the specified name, and construct a Font object from it.

Otherwise, it makes a font with the default encoding (MacRomanEncoding on Macs, WinAnsiEncoding elsewhere, or for symbol fonts, their own custom encoding). There is not a way to specify another encoding for the font.

When setting text, it checks to see if the text is representable in the font's encoding. If it is not, then DLE makes a "unicode font" with an Identity-H encoding and uses that to set the text. For non-Type0 fonts, this may result in two versions of a font in the output document.

PDFL enforces the following requirements on fonts:

TrueTypes used as CID fonts must be embedded.
All CID fonts that are embedded must be subsetted.
CID fonts that are marked as embedded get their DoNotEmbed flag turned off (or else PDFL won't make a PDEFont from the SysFont).

### Font

```csharp
Datalogics.PDFL.Font.Font(string fontName, FontCreateFlags createFlags)
```

*constructor*

**Parameters**

- `fontName` (`string`): the name of the font to create
- `createFlags` ([`FontCreateFlags`](https://docs.datalogics.com/apdfl18/DotNet/APDFL18.0.5PlusP2e/enum/FontCreateFlags.md)): flags specifying embedding and other options for the use of a font in the document

Find a font with the specified name, and construct a Font object from it.

Otherwise, it makes a font with the default encoding (MacRomanEncoding on Macs, WinAnsiEncoding elsewhere, or for symbol fonts, their own custom encoding). There is not a way to specify another encoding for the font.

When setting text, it checks to see if the text is representable in the font's encoding. If it is not, then DLE makes a "unicode font" with an Identity-H encoding and uses that to set the text. For non-Type0 fonts, this may result in two versions of a font in the output document.

PDFL enforces the following requirements on fonts:

TrueTypes used as CID fonts must be embedded.
All CID fonts that are embedded must be subsetted.
CID fonts that are marked as embedded get their DoNotEmbed flag turned off (or else PDFL won't make a PDEFont from the SysFont).

### Font

```csharp
Datalogics.PDFL.Font.Font(string fontName, FontCreateFlags createFlags, WritingMode wrMode)
```

*constructor*

**Parameters**

- `fontName` (`string`): the name of the font to create
- `createFlags` ([`FontCreateFlags`](https://docs.datalogics.com/apdfl18/DotNet/APDFL18.0.5PlusP2e/enum/FontCreateFlags.md)): flags specifying embedding and other options for the use of a font in the document
- `wrMode` ([`WritingMode`](https://docs.datalogics.com/apdfl18/DotNet/APDFL18.0.5PlusP2e/enum/WritingMode.md)): determines whether text will be printed horizontally or vertically

Find a font with the specified name, and construct a Font object from it.

Otherwise, it makes a font with the default encoding (MacRomanEncoding on Macs, WinAnsiEncoding elsewhere, or for symbol fonts, their own custom encoding). There is not a way to specify another encoding for the font.

When setting text, it checks to see if the text is representable in the font's encoding. If it is not, then DLE makes a "unicode font" with an Identity-H or Identity-V encoding and uses that to set the text. For non-Type0 fonts, this may result in two versions of a font in the output document.

PDFL enforces the following requirements on fonts:

TrueTypes used as CID fonts must be embedded.
All CID fonts that are embedded must be subsetted.
CID fonts that are marked as embedded get their DoNotEmbed flag turned off (or else PDFL won't make a PDEFont from the SysFont).

## Properties

### Ascent

```csharp
double Datalogics.PDFL.Font.Ascent { get; }
```

### AvgWidth

```csharp
double Datalogics.PDFL.Font.AvgWidth { get; }
```

### BBox

```csharp
Rect Datalogics.PDFL.Font.BBox { get; }
```

### CapHeight

```csharp
double Datalogics.PDFL.Font.CapHeight { get; }
```

### CidFontType

```csharp
string Datalogics.PDFL.Font.CidFontType { get; }
```

### Descent

```csharp
double Datalogics.PDFL.Font.Descent { get; }
```

### Embedded

```csharp
bool Datalogics.PDFL.Font.Embedded { get; }
```

### Encoding

```csharp
string Datalogics.PDFL.Font.Encoding { get; }
```

### EncodingInfo

```csharp
EncodingInfo Datalogics.PDFL.Font.EncodingInfo { get; }
```

### Flags

```csharp
FontFlags Datalogics.PDFL.Font.Flags { get; }
```

### FontList

```csharp
static System.Collections.Generic.IList<Font> Datalogics.PDFL.Font.FontList { get; }
```

*static*

### FullName

```csharp
string Datalogics.PDFL.Font.FullName { get; }
```

### ItalicAngle

```csharp
double Datalogics.PDFL.Font.ItalicAngle { get; }
```

### Leading

```csharp
double Datalogics.PDFL.Font.Leading { get; }
```

### MaxWidth

```csharp
double Datalogics.PDFL.Font.MaxWidth { get; }
```

### MissingWidth

```csharp
double Datalogics.PDFL.Font.MissingWidth { get; }
```

### Name

```csharp
string Datalogics.PDFL.Font.Name { get; }
```

### PDFDict

```csharp
PDFDict Datalogics.PDFL.Font.PDFDict { get; }
```

### StemH

```csharp
double Datalogics.PDFL.Font.StemH { get; }
```

### StemV

```csharp
double Datalogics.PDFL.Font.StemV { get; }
```

### Type

```csharp
string Datalogics.PDFL.Font.Type { get; }
```

### WritingMode

```csharp
WritingMode Datalogics.PDFL.Font.WritingMode { get; }
```

### XHeight

```csharp
double Datalogics.PDFL.Font.XHeight { get; }
```

## Methods

### Dispose

```csharp
void Datalogics.PDFL.Font.Dispose()
```

**Returns:** `void`

### EmbedNow

```csharp
void Datalogics.PDFL.Font.EmbedNow(Document doc)
```

**Parameters**

- `doc` ([`Document`](https://docs.datalogics.com/apdfl18/DotNet/APDFL18.0.5PlusP2e/class/Document.md)): the Document the Font is embedded into

**Returns:** `void`

Embeds the Font.

### FindIndexOfFirstUnrepresentableChar

```csharp
uint Datalogics.PDFL.Font.FindIndexOfFirstUnrepresentableChar(string text)
```

**Parameters**

- `text` (`string`): the text to check

**Returns:** `uint`

The index of the first character that cannot be represented in this font.

Find the index of the first character that cannot be represented in this font. This will return the index of the first character in the string for which the font has no glyph. If all characters can be represented (i.e. if IsTextRepresentable() would return true), this will return the length of the string.

### IsFromDoc

```csharp
bool Datalogics.PDFL.Font.IsFromDoc()
```

**Returns:** `bool`

true if the font was loaded from a document, false if it was created from a system font.

Determine whether this font was obtained from an existing document rather than the system.

### IsTextRepresentable

```csharp
bool Datalogics.PDFL.Font.IsTextRepresentable(string text)
```

**Parameters**

- `text` (`string`): the text to check

**Returns:** `bool`

true if all characters in the text have corresponding glyphs in this font.

Is this text representable in this font?

### MeasureTextWidth

```csharp
double Datalogics.PDFL.Font.MeasureTextWidth(string text, double fontSize)
```

**Parameters**

- `text` (`string`): the Text to be measured
- `fontSize` (`double`): the Font size to be used

**Returns:** `double`

The width of the text in points.

Measures the width of the specified text in points, using the Font at the specified size.
