Table of Contents

Class PdfFontFactory

Namespace
iText.Kernel.Font
Assembly
itext.kernel.dll

This class provides helpful methods for creating fonts ready to be used in a PdfDocument

public sealed class PdfFontFactory
Inheritance
PdfFontFactory
Inherited Members

Remarks

This class provides helpful methods for creating fonts ready to be used in a PdfDocument

Note, just created PdfFont is almost empty until it will be flushed, because it is impossible to fulfill font data until flush.

Constructors

PdfFontFactory()

public PdfFontFactory()

Methods

CreateFont()

Creates a new instance of default font, namely HELVETICA standard font with WINANSI encoding.

public static PdfFont CreateFont()

Returns

PdfFont

created font

Remarks

Creates a new instance of default font, namely HELVETICA standard font with WINANSI encoding. Note, if you want to reuse the same instance of default font, you may use GetDefaultFont().

CreateFont(byte[], string)

Created a PdfFont instance by the bytes of the underlying font program.

public static PdfFont CreateFont(byte[] fontProgram, string encoding)

Parameters

fontProgram byte[]

the bytes of the underlying font program

encoding string

the encoding of the font to be created. See PdfEncodings

Returns

PdfFont

created PdfFont instance

CreateFont(byte[], string, EmbeddingStrategy)

Created a PdfFont instance by the bytes of the underlying font program.

public static PdfFont CreateFont(byte[] fontProgram, string encoding, PdfFontFactory.EmbeddingStrategy embeddingStrategy)

Parameters

fontProgram byte[]

the bytes of the underlying font program

encoding string

the encoding of the font to be created. See PdfEncodings

embeddingStrategy PdfFontFactory.EmbeddingStrategy

the PdfFontFactory.EmbeddingStrategy which will define whether the font will be embedded

Returns

PdfFont

created PdfFont instance

CreateFont(byte[], string, EmbeddingStrategy, bool)

Created a PdfFont instance by the bytes of the underlying font program.

public static PdfFont CreateFont(byte[] fontProgram, string encoding, PdfFontFactory.EmbeddingStrategy embeddingStrategy, bool cached)

Parameters

fontProgram byte[]

the bytes of the underlying font program

encoding string

the encoding of the font to be created. See PdfEncodings

embeddingStrategy PdfFontFactory.EmbeddingStrategy

the PdfFontFactory.EmbeddingStrategy which will define whether the font will be embedded

cached bool

indicates whether the font will be cached

Returns

PdfFont

created PdfFont instance

CreateFont(byte[], EmbeddingStrategy)

Created a PdfFont instance by the bytes of the underlying font program.

public static PdfFont CreateFont(byte[] fontProgram, PdfFontFactory.EmbeddingStrategy embeddingStrategy)

Parameters

fontProgram byte[]

the bytes of the underlying font program

embeddingStrategy PdfFontFactory.EmbeddingStrategy

the PdfFontFactory.EmbeddingStrategy which will define whether the font will be embedded

Returns

PdfFont

created PdfFont instance

CreateFont(string)

Creates a PdfFont instance by the path of the font program file

public static PdfFont CreateFont(string fontProgram)

Parameters

fontProgram string

the path of the font program file

Returns

PdfFont

created PdfFont instance

CreateFont(string, string)

Creates a PdfFont instance by the path of the font program file and given encoding.

public static PdfFont CreateFont(string fontProgram, string encoding)

Parameters

fontProgram string

the path of the font program file

encoding string

the font encoding. See PdfEncodings

Returns

PdfFont

created PdfFont instance

CreateFont(string, string, EmbeddingStrategy)

Created a PdfFont instance given the path to the font file.

public static PdfFont CreateFont(string fontProgram, string encoding, PdfFontFactory.EmbeddingStrategy embeddingStrategy)

Parameters

fontProgram string

the font program file

encoding string

the encoding of the font to be created. See PdfEncodings

embeddingStrategy PdfFontFactory.EmbeddingStrategy

the PdfFontFactory.EmbeddingStrategy which will define whether the font will be embedded

Returns

PdfFont

created PdfFont instance

CreateFont(string, string, EmbeddingStrategy, bool)

Created a PdfFont instance given the path to the font file.

public static PdfFont CreateFont(string fontProgram, string encoding, PdfFontFactory.EmbeddingStrategy embeddingStrategy, bool cached)

Parameters

fontProgram string

the font program file

encoding string

the encoding of the font to be created. See PdfEncodings

embeddingStrategy PdfFontFactory.EmbeddingStrategy

the PdfFontFactory.EmbeddingStrategy which will define whether the font will be embedded

cached bool

indicates whether the font will be cached

Returns

PdfFont

created PdfFont instance

CreateFont(string, string, EmbeddingStrategy, PdfDocument)

Creates a PdfFont instance by the path of the font program file and given encoding and place it inside the PdfDocument.

public static PdfFont CreateFont(string fontProgram, string encoding, PdfFontFactory.EmbeddingStrategy embeddingStrategy, PdfDocument cacheTo)

Parameters

fontProgram string

the path of the font program file

encoding string

the font encoding. See PdfEncodings

embeddingStrategy PdfFontFactory.EmbeddingStrategy

the PdfFontFactory.EmbeddingStrategy which will define whether the font will be embedded

cacheTo PdfDocument

the PdfDocument to cache the font

Returns

PdfFont

created PdfFont instance

Remarks

Creates a PdfFont instance by the path of the font program file and given encoding and place it inside the PdfDocument . If such PdfFont has already been created and placed inside the PdfDocument , then retries its instance instead of creating.

CreateFont(string, string, PdfDocument)

Creates a PdfFont instance by the path of the font program file and given encoding and place it inside the PdfDocument.

public static PdfFont CreateFont(string fontProgram, string encoding, PdfDocument cacheTo)

Parameters

fontProgram string

the path of the font program file

encoding string

the font encoding. See PdfEncodings

cacheTo PdfDocument

the PdfDocument to cache the font

Returns

PdfFont

created PdfFont instance

Remarks

Creates a PdfFont instance by the path of the font program file and given encoding and place it inside the PdfDocument . If such PdfFont has already been created and placed inside the PdfDocument , then retries its instance instead of creating. PREFER_EMBEDDED will be used as embedding strategy.

CreateFont(string, EmbeddingStrategy)

Created a PdfFont instance given the path to the font file.

public static PdfFont CreateFont(string fontProgram, PdfFontFactory.EmbeddingStrategy embeddingStrategy)

Parameters

fontProgram string

the font program file

embeddingStrategy PdfFontFactory.EmbeddingStrategy

the PdfFontFactory.EmbeddingStrategy which will define whether the font will be embedded

Returns

PdfFont

created PdfFont instance

CreateFont(FontProgram)

Created a PdfFont instance given the given underlying FontProgram instance.

public static PdfFont CreateFont(FontProgram fontProgram)

Parameters

fontProgram FontProgram

the font program of the PdfFont instance to be created

Returns

PdfFont

created PdfFont instance

CreateFont(FontProgram, string)

Created a PdfFont instance given the given underlying FontProgram instance.

public static PdfFont CreateFont(FontProgram fontProgram, string encoding)

Parameters

fontProgram FontProgram

the font program of the PdfFont instance to be created

encoding string

the encoding of the font to be created. See PdfEncodings

Returns

PdfFont

created PdfFont instance

CreateFont(FontProgram, string, EmbeddingStrategy)

Created a PdfFont instance given the given underlying FontProgram instance.

public static PdfFont CreateFont(FontProgram fontProgram, string encoding, PdfFontFactory.EmbeddingStrategy embeddingStrategy)

Parameters

fontProgram FontProgram

the font program of the PdfFont instance to be created

encoding string

the encoding of the font to be created. See PdfEncodings

embeddingStrategy PdfFontFactory.EmbeddingStrategy

the PdfFontFactory.EmbeddingStrategy which will define whether the font will be embedded

Returns

PdfFont

created PdfFont instance

CreateFont(PdfDictionary)

Creates a PdfFont by already existing font dictionary.

public static PdfFont CreateFont(PdfDictionary fontDictionary)

Parameters

fontDictionary PdfDictionary

the font dictionary to create the font from

Returns

PdfFont

created PdfFont instance

Remarks

Creates a PdfFont by already existing font dictionary.

Note, the font won't be added to any document, until you add it to PdfCanvas. While adding to PdfCanvas , or to PdfResources the font will be made indirect implicitly.

GetFont(PdfDictionary) method is strongly recommended if you want to get PdfFont by both existing font dictionary, or just created and hasn't flushed yet.

CreateRegisteredFont(string)

Creates PdfFont based on registered FontProgram 's.

public static PdfFont CreateRegisteredFont(string fontName)

Parameters

fontName string

Path to font file or Standard font name

Returns

PdfFont

created font if required FontProgram was found among registered, otherwise null.

Remarks

Creates PdfFont based on registered FontProgram 's. Required font program is expected to be previously registered by one of the register method from PdfFontFactory.

See Also

CreateRegisteredFont(string, string)

Creates PdfFont based on registered FontProgram 's.

public static PdfFont CreateRegisteredFont(string fontName, string encoding)

Parameters

fontName string

Path to font file or Standard font name

encoding string

Font encoding from PdfEncodings.

Returns

PdfFont

created font if required FontProgram was found among registered, otherwise null.

Remarks

Creates PdfFont based on registered FontProgram 's. Required font program is expected to be previously registered by one of the register method from PdfFontFactory.

See Also

CreateRegisteredFont(string, string, EmbeddingStrategy)

Creates PdfFont based on registered FontProgram 's.

public static PdfFont CreateRegisteredFont(string fontName, string encoding, PdfFontFactory.EmbeddingStrategy embeddingStrategy)

Parameters

fontName string

Path to font file or Standard font name

encoding string

Font encoding from PdfEncodings.

embeddingStrategy PdfFontFactory.EmbeddingStrategy

the PdfFontFactory.EmbeddingStrategy which will define whether the font will be embedded. Note, standard font won't be embedded in any case.

Returns

PdfFont

created font if required FontProgram was found among registered, otherwise null.

Remarks

Creates PdfFont based on registered FontProgram 's. Required font program is expected to be previously registered by one of the register method from PdfFontFactory.

See Also

CreateRegisteredFont(string, string, EmbeddingStrategy, bool)

Creates PdfFont based on registered FontProgram 's.

public static PdfFont CreateRegisteredFont(string fontName, string encoding, PdfFontFactory.EmbeddingStrategy embeddingStrategy, bool cached)

Parameters

fontName string

Path to font file or Standard font name

encoding string

Font encoding from PdfEncodings.

embeddingStrategy PdfFontFactory.EmbeddingStrategy

the PdfFontFactory.EmbeddingStrategy which will define whether the font will be embedded. Note, standard font won't be embedded in any case.

cached bool

If true font will be cached for another PdfDocument

Returns

PdfFont

created font if required FontProgram was found among registered, otherwise null.

Remarks

Creates PdfFont based on registered FontProgram 's. Required font program is expected to be previously registered by one of the register method from PdfFontFactory.

See Also

CreateRegisteredFont(string, string, EmbeddingStrategy, int)

Creates PdfFont based on registered FontProgram 's.

public static PdfFont CreateRegisteredFont(string fontName, string encoding, PdfFontFactory.EmbeddingStrategy embeddingStrategy, int style)

Parameters

fontName string

Path to font file or Standard font name

encoding string

Font encoding from PdfEncodings.

embeddingStrategy PdfFontFactory.EmbeddingStrategy

the PdfFontFactory.EmbeddingStrategy which will define whether the font will be embedded. Note, standard font won't be embedded in any case.

style int

Font style from FontStyles.

Returns

PdfFont

created font if required FontProgram was found among registered, otherwise null.

Remarks

Creates PdfFont based on registered FontProgram 's. Required font program is expected to be previously registered by one of the register method from PdfFontFactory.

See Also

CreateRegisteredFont(string, string, EmbeddingStrategy, int, bool)

Creates PdfFont based on registered FontProgram 's.

public static PdfFont CreateRegisteredFont(string fontName, string encoding, PdfFontFactory.EmbeddingStrategy embeddingStrategy, int style, bool cached)

Parameters

fontName string

Path to font file or Standard font name

encoding string

Font encoding from PdfEncodings.

embeddingStrategy PdfFontFactory.EmbeddingStrategy

the PdfFontFactory.EmbeddingStrategy which will define whether the font will be embedded. Note, standard font won't be embedded in any case.

style int

Font style from FontStyles.

cached bool

If true font will be cached for another PdfDocument

Returns

PdfFont

created font if required FontProgram was found among registered, otherwise null.

Remarks

Creates PdfFont based on registered FontProgram 's. Required font program is expected to be previously registered by one of the register method from PdfFontFactory.

See Also

CreateTtcFont(byte[], int, string, EmbeddingStrategy, bool)

Creates a PdfFont instance from the TrueType Collection represented by its byte contents.

public static PdfFont CreateTtcFont(byte[] ttc, int ttcIndex, string encoding, PdfFontFactory.EmbeddingStrategy embeddingStrategy, bool cached)

Parameters

ttc byte[]

the byte contents of the TrueType Collection

ttcIndex int

the index of the font in the collection, zero-based

encoding string

the encoding of the font to be created. See PdfEncodings

embeddingStrategy PdfFontFactory.EmbeddingStrategy

the PdfFontFactory.EmbeddingStrategy which will define whether the font will be embedded

cached bool

indicates whether the font will be cached

Returns

PdfFont

created PdfFont instance

CreateTtcFont(string, int, string, EmbeddingStrategy, bool)

Creates a PdfFont instance from the TrueType Collection given by the path to the .ttc file.

public static PdfFont CreateTtcFont(string ttc, int ttcIndex, string encoding, PdfFontFactory.EmbeddingStrategy embeddingStrategy, bool cached)

Parameters

ttc string

the path of the .ttc file

ttcIndex int

the index of the font in the collection, zero-based

encoding string

the encoding of the font to be created. See PdfEncodings

embeddingStrategy PdfFontFactory.EmbeddingStrategy

the PdfFontFactory.EmbeddingStrategy which will define whether the font will be embedded

cached bool

indicates whether the font will be cached

Returns

PdfFont

created PdfFont instance

CreateType3Font(PdfDocument, bool)

Creates a new instance of PdfType3Font

public static PdfType3Font CreateType3Font(PdfDocument document, bool colorized)

Parameters

document PdfDocument

the target document of the new font

colorized bool

indicates whether the font will be colorized

Returns

PdfType3Font

created font

CreateType3Font(PdfDocument, string, string, bool)

Creates a new instance of PdfType3Font

public static PdfType3Font CreateType3Font(PdfDocument document, string fontName, string fontFamily, bool colorized)

Parameters

document PdfDocument

the target document of the new font.

fontName string

the PostScript name of the font, shall not be null or empty.

fontFamily string

a preferred font family name.

colorized bool

indicates whether the font will be colorized

Returns

PdfType3Font

created font.

GetRegisteredFamilies()

Gets a set of registered font families.

public static ICollection<string> GetRegisteredFamilies()

Returns

ICollection<string>

a set of registered font families

GetRegisteredFonts()

Gets a set of registered font names.

public static ICollection<string> GetRegisteredFonts()

Returns

ICollection<string>

a set of registered fonts

IsRegistered(string)

Checks if a certain font is registered.

public static bool IsRegistered(string fontName)

Parameters

fontName string

the name of the font that has to be checked.

Returns

bool

true if the font is found, false otherwise

Register(string)

Registers a .ttf, .otf, .afm, .pfm, or a .ttc font file.

public static void Register(string path)

Parameters

path string

the path to a font file

Remarks

Registers a .ttf, .otf, .afm, .pfm, or a .ttc font file. In case if TrueType Collection (.ttc), an additional parameter may be specified defining the index of the font to be registered, e.g. "path/to/font/collection.ttc,0". The index is zero-based.

Register(string, string)

Register a font file and use an alias for the font contained in it.

public static void Register(string path, string alias)

Parameters

path string

the path to a font file

alias string

the alias you want to use for the font

RegisterDirectory(string)

Registers all the fonts in a directory.

public static int RegisterDirectory(string dirPath)

Parameters

dirPath string

the directory path to be registered as a font directory path

Returns

int

the number of fonts registered

RegisterFamily(string, string, string)

Register a font by giving explicitly the font family and name.

public static void RegisterFamily(string familyName, string fullName, string path)

Parameters

familyName string

the font family

fullName string

the font name

path string

the font path

RegisterSystemDirectories()

Register fonts in some probable directories.

public static int RegisterSystemDirectories()

Returns

int

the number of fonts registered

Remarks

Register fonts in some probable directories. It usually works in Windows, Linux and Solaris.