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, 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 a .ttf.stream or .otf.stream file, the fonts PDFjet shipped before 9.0.5, opens the .ttf or else the .otf file of the same name beside it.

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

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)

Enables or disables kerning. Kerning is only supported for the 14 standard fonts.

public Font SetKernPairs(bool kernPairs)

Parameters

kernPairs bool

Returns

Font

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