# PdfOpenTypeFont class

> A TrueType or OpenType font, embedded in the document as a subset of the glyphs actually drawn. Loads .ttf, .otf, collections (.ttc, .otc), WOFF and...

Namespace: [PdfNetStack.Fonts](https://www.jadev-corp.com/api/pdfnetstack-fonts/)  
Assembly: PdfNetStack.dll  
Package: `PdfNetStack`

A TrueType or OpenType font, embedded in the document as a subset of the glyphs actually drawn.
Loads .ttf, .otf, collections (.ttc, .otc), WOFF and WOFF2 files. Text is searchable and
copyable, and pairs are kerned from the font's GPOS or kern table.

```csharp
public sealed class PdfOpenTypeFont : PdfFont
```

**Inheritance**

[object](https://learn.microsoft.com/dotnet/api/system.object) ← 
[PdfFont](https://www.jadev-corp.com/api/pdfnetstack-fonts/pdffont/) ← 
[PdfOpenTypeFont](https://www.jadev-corp.com/api/pdfnetstack-fonts/pdfopentypefont/)

## Remarks

The font program is embedded, so the PDF shows the same glyphs everywhere, including in PDF/A.
A variable font draws its default instance; [GetInstance](https://www.jadev-corp.com/api/pdfnetstack-fonts/pdfopentypefont/#PdfNetStack_Fonts_PdfOpenTypeFont_GetInstance_System_String_) and
[GetInstance](https://www.jadev-corp.com/api/pdfnetstack-fonts/pdfopentypefont/#PdfNetStack_Fonts_PdfOpenTypeFont_GetInstance_System_Collections_Generic_IReadOnlyDictionary_System_String_System_Double__) give any other, embedded as a
static font with the variations applied (TrueType and CFF2 outlines alike). Each location is
made once and shared while it is in use, the default location being the font itself, so a
document embeds one program per location drawn; instances nothing holds any more are freed.
Fonts whose license forbids embedding (OS/2 fsType) are refused when first drawn.

## Properties

### <a id="PdfNetStack_Fonts_PdfOpenTypeFont_AllowsEmbedding"></a> AllowsEmbedding

True when the font's license (OS/2 fsType) allows embedding it in a document.

```csharp
public bool AllowsEmbedding { get; }
```

#### Property Value

 [bool](https://learn.microsoft.com/dotnet/api/system.boolean)

### <a id="PdfNetStack_Fonts_PdfOpenTypeFont_FamilyName"></a> FamilyName

Family name, such as "Helvetica".

```csharp
public override string FamilyName { get; }
```

#### Property Value

 [string](https://learn.microsoft.com/dotnet/api/system.string)

### <a id="PdfNetStack_Fonts_PdfOpenTypeFont_GlyphCount"></a> GlyphCount

Number of glyphs in the font.

```csharp
public int GlyphCount { get; }
```

#### Property Value

 [int](https://learn.microsoft.com/dotnet/api/system.int32)

### <a id="PdfNetStack_Fonts_PdfOpenTypeFont_IsBold"></a> IsBold

True for bold and heavier weights.

```csharp
public override bool IsBold { get; }
```

#### Property Value

 [bool](https://learn.microsoft.com/dotnet/api/system.boolean)

### <a id="PdfNetStack_Fonts_PdfOpenTypeFont_IsFixedPitch"></a> IsFixedPitch

True when all glyphs have the same advance.

```csharp
public bool IsFixedPitch { get; }
```

#### Property Value

 [bool](https://learn.microsoft.com/dotnet/api/system.boolean)

### <a id="PdfNetStack_Fonts_PdfOpenTypeFont_IsItalic"></a> IsItalic

True for italic and oblique styles.

```csharp
public override bool IsItalic { get; }
```

#### Property Value

 [bool](https://learn.microsoft.com/dotnet/api/system.boolean)

### <a id="PdfNetStack_Fonts_PdfOpenTypeFont_IsVariable"></a> IsVariable

True for a variable font: one with design axes that [GetInstance](https://www.jadev-corp.com/api/pdfnetstack-fonts/pdfopentypefont/#PdfNetStack_Fonts_PdfOpenTypeFont_GetInstance_System_Collections_Generic_IReadOnlyDictionary_System_String_System_Double__) can set.

```csharp
public bool IsVariable { get; }
```

#### Property Value

 [bool](https://learn.microsoft.com/dotnet/api/system.boolean)

### <a id="PdfNetStack_Fonts_PdfOpenTypeFont_Name"></a> Name

PostScript name, as written to /BaseFont.

```csharp
public override string Name { get; }
```

#### Property Value

 [string](https://learn.microsoft.com/dotnet/api/system.string)

### <a id="PdfNetStack_Fonts_PdfOpenTypeFont_NamedInstances"></a> NamedInstances

The style names of a variable font's named instances, such as "Bold" or "Condensed Light"; empty for a static font.

```csharp
public IReadOnlyList<string> NamedInstances { get; }
```

#### Property Value

 [IReadOnlyList](https://learn.microsoft.com/dotnet/api/system.collections.generic.ireadonlylist\-1)<[string](https://learn.microsoft.com/dotnet/api/system.string)\>

### <a id="PdfNetStack_Fonts_PdfOpenTypeFont_StyleName"></a> StyleName

Style name within the family, such as "Bold Italic".

```csharp
public string StyleName { get; }
```

#### Property Value

 [string](https://learn.microsoft.com/dotnet/api/system.string)

### <a id="PdfNetStack_Fonts_PdfOpenTypeFont_VariationAxes"></a> VariationAxes

The design axes of a variable font; empty for a static font.

```csharp
public IReadOnlyList<PdfFontAxis> VariationAxes { get; }
```

#### Property Value

 [IReadOnlyList](https://learn.microsoft.com/dotnet/api/system.collections.generic.ireadonlylist\-1)<[PdfFontAxis](https://www.jadev-corp.com/api/pdfnetstack-fonts/pdffontaxis/)\>

### <a id="PdfNetStack_Fonts_PdfOpenTypeFont_Weight"></a> Weight

Weight from 1 to 1000: 400 is regular, 700 bold.

```csharp
public int Weight { get; }
```

#### Property Value

 [int](https://learn.microsoft.com/dotnet/api/system.int32)

## Methods

### <a id="PdfNetStack_Fonts_PdfOpenTypeFont_CountFonts_System_Byte___"></a> CountFonts\(byte\[\]\)

Number of fonts in a file's bytes: more than one for a collection.

```csharp
public static int CountFonts(byte[] data)
```

#### Parameters

`data` [byte](https://learn.microsoft.com/dotnet/api/system.byte)\[\]

#### Returns

 [int](https://learn.microsoft.com/dotnet/api/system.int32)

### <a id="PdfNetStack_Fonts_PdfOpenTypeFont_GetInstance_System_String_"></a> GetInstance\(string\)

The variable font at one of its named instances, as a static font: outlines, advances and
metrics follow the instance, and shaping applies its kerning and substitutions.

```csharp
public PdfOpenTypeFont GetInstance(string name)
```

#### Parameters

`name` [string](https://learn.microsoft.com/dotnet/api/system.string)

A style name from [NamedInstances](https://www.jadev-corp.com/api/pdfnetstack-fonts/pdfopentypefont/#PdfNetStack_Fonts_PdfOpenTypeFont_NamedInstances), compared without regard to case.

#### Returns

 [PdfOpenTypeFont](https://www.jadev-corp.com/api/pdfnetstack-fonts/pdfopentypefont/)

#### Exceptions

 [InvalidOperationException](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception)

The font is not variable.

 [ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception)

The font has no instance of that name.

 [FontFormatException](https://www.jadev-corp.com/api/pdfnetstack-fonts/fontformatexception/)

The font's variation data is damaged.

### <a id="PdfNetStack_Fonts_PdfOpenTypeFont_GetInstance_System_Collections_Generic_IReadOnlyDictionary_System_String_System_Double__"></a> GetInstance\(IReadOnlyDictionary&lt;string, double\>\)

The variable font at the given axis values, as a static font. Axes not named keep their
default; values outside an axis's range are clamped to it.

```csharp
public PdfOpenTypeFont GetInstance(IReadOnlyDictionary<string, double> axisValues)
```

#### Parameters

`axisValues` [IReadOnlyDictionary](https://learn.microsoft.com/dotnet/api/system.collections.generic.ireadonlydictionary\-2)<[string](https://learn.microsoft.com/dotnet/api/system.string), [double](https://learn.microsoft.com/dotnet/api/system.double)\>

Values by axis tag, in the axis's own units, such as <code>{ ["wght"] = 650 }</code>.

#### Returns

 [PdfOpenTypeFont](https://www.jadev-corp.com/api/pdfnetstack-fonts/pdfopentypefont/)

#### Exceptions

 [InvalidOperationException](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception)

The font is not variable.

 [ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception)

A tag is not one of the font's axes, or a value is not a number.

 [FontFormatException](https://www.jadev-corp.com/api/pdfnetstack-fonts/fontformatexception/)

The font's variation data is damaged.

### <a id="PdfNetStack_Fonts_PdfOpenTypeFont_Load_System_String_System_Int32_"></a> Load\(string, int\)

Loads a font from a file: .ttf, .otf, .ttc, .otc, .woff or .woff2.

```csharp
public static PdfOpenTypeFont Load(string path, int index = 0)
```

#### Parameters

`path` [string](https://learn.microsoft.com/dotnet/api/system.string)

The font file.

`index` [int](https://learn.microsoft.com/dotnet/api/system.int32)

For a collection, which of its fonts; see [CountFonts](https://www.jadev-corp.com/api/pdfnetstack-fonts/pdfopentypefont/#PdfNetStack_Fonts_PdfOpenTypeFont_CountFonts_System_Byte___).

#### Returns

 [PdfOpenTypeFont](https://www.jadev-corp.com/api/pdfnetstack-fonts/pdfopentypefont/)

#### Exceptions

 [FontFormatException](https://www.jadev-corp.com/api/pdfnetstack-fonts/fontformatexception/)

The file is not a supported font.

### <a id="PdfNetStack_Fonts_PdfOpenTypeFont_Load_System_IO_Stream_System_Int32_"></a> Load\(Stream, int\)

Loads a font from a stream, read to its end.

```csharp
public static PdfOpenTypeFont Load(Stream stream, int index = 0)
```

#### Parameters

`stream` [Stream](https://learn.microsoft.com/dotnet/api/system.io.stream)

`index` [int](https://learn.microsoft.com/dotnet/api/system.int32)

#### Returns

 [PdfOpenTypeFont](https://www.jadev-corp.com/api/pdfnetstack-fonts/pdfopentypefont/)

#### Exceptions

 [FontFormatException](https://www.jadev-corp.com/api/pdfnetstack-fonts/fontformatexception/)

The data is not a supported font.

### <a id="PdfNetStack_Fonts_PdfOpenTypeFont_Load_System_Byte___System_Int32_"></a> Load\(byte\[\], int\)

Loads a font from its bytes. The array is used directly; do not change it afterwards.

```csharp
public static PdfOpenTypeFont Load(byte[] data, int index = 0)
```

#### Parameters

`data` [byte](https://learn.microsoft.com/dotnet/api/system.byte)\[\]

`index` [int](https://learn.microsoft.com/dotnet/api/system.int32)

#### Returns

 [PdfOpenTypeFont](https://www.jadev-corp.com/api/pdfnetstack-fonts/pdfopentypefont/)

#### Exceptions

 [FontFormatException](https://www.jadev-corp.com/api/pdfnetstack-fonts/fontformatexception/)

The data is not a supported font.

## Used in

- [Compress PDF files in C# and .NET](https://www.jadev-corp.com/guides/compress-pdf/)
- [Fonts and text in PDF with C# and .NET](https://www.jadev-corp.com/guides/fonts-and-text/)
- [Create PDF/A files in C# and .NET](https://www.jadev-corp.com/guides/pdf-a/)
- [Add page numbers to a PDF in C#](https://www.jadev-corp.com/recipes/add-page-numbers/)
- [Write Arabic text in a PDF in C#](https://www.jadev-corp.com/recipes/arabic-text-pdf/)
- [Create a Factur-X invoice PDF in C#](https://www.jadev-corp.com/recipes/pdf-a-3-xml-attachment/)

Source: https://www.jadev-corp.com/pdfnetstack/api/pdfnetstack-fonts/pdfopentypefont/
