Table of Contents

Class Font

Namespace
PDFjet.NET
Assembly
PDFjet.dll

Used to create font objects. The font objects must be added to the PDF before they can be used to draw text.

public class Font
Inheritance
Font
Inherited Members

Constructors

Font(PDF, CJKFont)

Creates a Chinese, Japanese or Korean font and adds it to the PDF, not embedded: the viewer supplies it.

public Font(PDF pdf, CJKFont font)

Parameters

pdf PDF
font CJKFont

Font(PDF, byte[])

Constructor for OpenType and TrueType fonts, .otf and .ttf, from the bytes of the font file, such as an app's resource read whole. The font keeps the bytes, as a shaper is given them to the text engine that shapes it.

public Font(PDF pdf, byte[] fontFile)

Parameters

pdf PDF

the PDF object that requires this font.

fontFile byte[]

the bytes of the font file.

Font(PDF, Stream)

Constructor for OpenType and TrueType fonts, .otf and .ttf.

public Font(PDF pdf, Stream inputStream)

Parameters

pdf PDF

the PDF object that requires this font.

inputStream Stream

the input stream to read this font from.

Font(PDF, int)

Constructor for the 14 standard fonts. Creates a font object and adds it to the PDF.

Examples:
    Font font1 = new Font(pdf, CoreFont.HELVETICA);
    Font font2 = new Font(pdf, CoreFont.TIMES_ITALIC);
    Font font3 = new Font(pdf, CoreFont.ZAPF_DINGBATS);
     ...
public Font(PDF pdf, int coreFont)

Parameters

pdf PDF

the PDF to add this font to.

coreFont int

the core font. Must be one the names defined in the CoreFont class.

Font(PDF, string)

Constructor for OpenType and TrueType fonts, .otf and .ttf files. A path to one of the fonts PDFjet carries, such as the constants of the font classes, fonts/IBMPlexSans/IBMPlexSans-Regular.otf for one, is read from the folder resources/fonts, else from the library, when there is no such file: the NuGet package PDFjet carries the European fonts; the others, such as IBMPlexSansJP.Regular and IBMPlexSansArabic.Regular, are in the NuGet package PDFjet.Fonts.World, which a program adds next to PDFjet, and such a font not found says so. The fonts PDFjet carries are .otf files: a path to a .ttf of one of them, such as fonts/IBMPlexSans/IBMPlexSans-Regular.ttf, that is not a file throws, and names the .otf path and the constant to write.

public Font(PDF pdf, string fontPath)

Parameters

pdf PDF

the pdf object.

fontPath string

the font path.

Exceptions

Exception

thrown if the font file is not found.

Font(List<PDFobj>, Stream)

Creates a font from an OpenType or TrueType font, a .otf or a .ttf, and adds it to the objects of an existing PDF. It is embedded as a subset of the glyphs drawn, when the objects are added to the PDF, unless SetSubset(false) keeps it whole.

public Font(List<PDFobj> objects, Stream inputStream)

Parameters

objects List<PDFobj>
inputStream Stream

Font(List<PDFobj>, string)

Constructor for OpenType and TrueType fonts, .otf and .ttf files, added to the objects of an existing PDF. A path to one of the fonts PDFjet carries, such as the constants of the font classes, is read from the library when there is no such file, as by the constructor that takes a PDF and a path.

public Font(List<PDFobj> objects, string fontPath)

Parameters

objects List<PDFobj>

the list of objects

fontPath string

the font path

Exceptions

FileNotFoundException

thrown if the font is not found.

Methods

GetAscent()

Returns the ascent at the current font size.

public float GetAscent()

Returns

float

GetAscent(float)

Returns the ascent at the specified font size.

public float GetAscent(float fontSize)

Parameters

fontSize float

Returns

float

GetBodyHeight()

Returns the height of the body of this font.

public float GetBodyHeight()

Returns

float

the height of the body of the font.

GetBodyHeight(float)

Returns the ascent plus the descent at the specified font size.

public float GetBodyHeight(float fontSize)

Parameters

fontSize float

Returns

float

GetDescent()

Returns the descent at the current font size.

public float GetDescent()

Returns

float

GetDescent(float)

Returns the descent at the specified font size.

public float GetDescent(float fontSize)

Parameters

fontSize float

Returns

float

GetFitChars(string, float)

Returns how many characters of the string fit within the specified width, counted in the UTF-16 chars of the string, so that it can be passed to Substring.

public int GetFitChars(string str, float width)

Parameters

str string
width float

Returns

int

GetLineGap(float)

Returns the line gap at the specified font size: the space the font puts between the descent of a line and the ascent of the next one. It is 0 for most fonts, which leave that space in their ascent and descent, and 1 em for the Japanese and Chinese IBM Plex fonts, whose ascent and descent add up to 1 em.

public float GetLineGap(float fontSize)

Parameters

fontSize float

Returns

float

GetName()

Returns the name of the font.

public string GetName()

Returns

string

GetSize()

Returns the font size.

public float GetSize()

Returns

float

GetUnderlinePosition()

Returns the underline position at the current font size.

public float GetUnderlinePosition()

Returns

float

GetUnderlinePosition(float)

Returns the underline position at the specified font size.

public float GetUnderlinePosition(float fontSize)

Parameters

fontSize float

Returns

float

GetUnderlineThickness()

Returns the underline thickness at the current font size.

public float GetUnderlineThickness()

Returns

float

GetUnderlineThickness(float)

Returns the underline thickness at the specified font size.

public float GetUnderlineThickness(float fontSize)

Parameters

fontSize float

Returns

float

SetItalic(bool)

Sets the skew15 private variable. When the variable is set to 'true' all glyphs in the font are skewed on 15 degrees. This makes a regular font look like an italic type font. Use this method when you don't have real italic font in the font family, or when you want to generate smaller PDF files. For example you could embed only the Regular and Bold fonts and synthesize the RegularItalic and BoldItalic.

public Font SetItalic(bool skew15)

Parameters

skew15 bool

the skew flag.

Returns

Font

this Font object.

SetKernPairs(bool)

Turns the kerning of the font on or off: the pairs of letters that go closer together or further apart, as AV and To. A standard font kerns with the pairs of its metrics; an OpenType or TrueType font with the kern feature of its GPOS table. Off by default, as text that does not ask for it is as fast as it was. A kerned font measures its text as it draws it: StringWidth, the wrapping and the alignment of TextLine, TextBlock and the table cells count the pairs. Right to left text and marks are not kerned.

public Font SetKernPairs(bool kernPairs)

Parameters

kernPairs bool

true to kern the text drawn with the font.

Returns

Font

this Font object.

SetSize(float)

public Font SetSize(float fontSize)

Parameters

fontSize float

Returns

Font

SetSubset(bool)

Sets whether this font is embedded as a subset, the outlines of the glyphs the document does not draw left out, which is the default for a .ttf or a .otf. A font whose license does not allow subsetting, by the fsType of its OS/2 table, is embedded whole. Fonts read from one file are one font program in the PDF: kept whole for one, the program is whole for all of them. It must be called before Complete(), and for a font added to the objects of an existing PDF, before the objects are added to the PDF.

public Font SetSubset(bool subset)

Parameters

subset bool

false to embed the font whole.

Returns

Font

this Font object.

StringWidth(Font, float, string)

Returns the width of a string drawn using two fonts.

public float StringWidth(Font fallbackFont, float fontSize, string str)

Parameters

fallbackFont Font

the fallback font.

fontSize float

the font size.

str string

the string.

Returns

float

the width.

StringWidth(Font, string)

Returns the width of the string at the current font size, using the fallback font for characters this font does not have.

public float StringWidth(Font fallbackFont, string str)

Parameters

fallbackFont Font
str string

Returns

float

StringWidth(float, string)

Returns the width of the string at the specified font size.

public float StringWidth(float fontSize, string str)

Parameters

fontSize float
str string

Returns

float

StringWidth(string)

Returns the width of the string at the current font size.

public float StringWidth(string str)

Parameters

str string

Returns

float