Class PdfFontFactory
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()
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
stringthe encoding of the font to be created. See PdfEncodings
Returns
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
stringthe encoding of the font to be created. See PdfEncodings
embeddingStrategy
PdfFontFactory.EmbeddingStrategythe PdfFontFactory.EmbeddingStrategy which will define whether the font will be embedded
Returns
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
stringthe encoding of the font to be created. See PdfEncodings
embeddingStrategy
PdfFontFactory.EmbeddingStrategythe PdfFontFactory.EmbeddingStrategy which will define whether the font will be embedded
cached
boolindicates whether the font will be cached
Returns
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.EmbeddingStrategythe PdfFontFactory.EmbeddingStrategy which will define whether the font will be embedded
Returns
CreateFont(string)
Creates a PdfFont instance by the path of the font program file
public static PdfFont CreateFont(string fontProgram)
Parameters
fontProgram
stringthe path of the font program file
Returns
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
stringthe path of the font program file
encoding
stringthe font encoding. See PdfEncodings
Returns
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
stringthe font program file
encoding
stringthe encoding of the font to be created. See PdfEncodings
embeddingStrategy
PdfFontFactory.EmbeddingStrategythe PdfFontFactory.EmbeddingStrategy which will define whether the font will be embedded
Returns
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
stringthe font program file
encoding
stringthe encoding of the font to be created. See PdfEncodings
embeddingStrategy
PdfFontFactory.EmbeddingStrategythe PdfFontFactory.EmbeddingStrategy which will define whether the font will be embedded
cached
boolindicates whether the font will be cached
Returns
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
stringthe path of the font program file
encoding
stringthe font encoding. See PdfEncodings
embeddingStrategy
PdfFontFactory.EmbeddingStrategythe PdfFontFactory.EmbeddingStrategy which will define whether the font will be embedded
cacheTo
PdfDocumentthe PdfDocument to cache the font
Returns
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
stringthe path of the font program file
encoding
stringthe font encoding. See PdfEncodings
cacheTo
PdfDocumentthe PdfDocument to cache the font
Returns
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
stringthe font program file
embeddingStrategy
PdfFontFactory.EmbeddingStrategythe PdfFontFactory.EmbeddingStrategy which will define whether the font will be embedded
Returns
CreateFont(FontProgram)
Created a PdfFont instance given the given underlying FontProgram instance.
public static PdfFont CreateFont(FontProgram fontProgram)
Parameters
fontProgram
FontProgramthe font program of the PdfFont instance to be created
Returns
CreateFont(FontProgram, string)
Created a PdfFont instance given the given underlying FontProgram instance.
public static PdfFont CreateFont(FontProgram fontProgram, string encoding)
Parameters
fontProgram
FontProgramthe font program of the PdfFont instance to be created
encoding
stringthe encoding of the font to be created. See PdfEncodings
Returns
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
FontProgramthe font program of the PdfFont instance to be created
encoding
stringthe encoding of the font to be created. See PdfEncodings
embeddingStrategy
PdfFontFactory.EmbeddingStrategythe PdfFontFactory.EmbeddingStrategy which will define whether the font will be embedded
Returns
CreateFont(PdfDictionary)
Creates a PdfFont by already existing font dictionary.
public static PdfFont CreateFont(PdfDictionary fontDictionary)
Parameters
fontDictionary
PdfDictionarythe font dictionary to create the font from
Returns
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
stringPath 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
stringPath to font file or Standard font name
encoding
stringFont 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
stringPath to font file or Standard font name
encoding
stringFont encoding from PdfEncodings.
embeddingStrategy
PdfFontFactory.EmbeddingStrategythe 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
stringPath to font file or Standard font name
encoding
stringFont encoding from PdfEncodings.
embeddingStrategy
PdfFontFactory.EmbeddingStrategythe PdfFontFactory.EmbeddingStrategy which will define whether the font will be embedded. Note, standard font won't be embedded in any case.
cached
boolIf 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
stringPath to font file or Standard font name
encoding
stringFont encoding from PdfEncodings.
embeddingStrategy
PdfFontFactory.EmbeddingStrategythe PdfFontFactory.EmbeddingStrategy which will define whether the font will be embedded. Note, standard font won't be embedded in any case.
style
intFont 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
stringPath to font file or Standard font name
encoding
stringFont encoding from PdfEncodings.
embeddingStrategy
PdfFontFactory.EmbeddingStrategythe PdfFontFactory.EmbeddingStrategy which will define whether the font will be embedded. Note, standard font won't be embedded in any case.
style
intFont style from FontStyles.
cached
boolIf 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
intthe index of the font in the collection, zero-based
encoding
stringthe encoding of the font to be created. See PdfEncodings
embeddingStrategy
PdfFontFactory.EmbeddingStrategythe PdfFontFactory.EmbeddingStrategy which will define whether the font will be embedded
cached
boolindicates whether the font will be cached
Returns
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
stringthe path of the .ttc file
ttcIndex
intthe index of the font in the collection, zero-based
encoding
stringthe encoding of the font to be created. See PdfEncodings
embeddingStrategy
PdfFontFactory.EmbeddingStrategythe PdfFontFactory.EmbeddingStrategy which will define whether the font will be embedded
cached
boolindicates whether the font will be cached
Returns
CreateType3Font(PdfDocument, bool)
Creates a new instance of PdfType3Font
public static PdfType3Font CreateType3Font(PdfDocument document, bool colorized)
Parameters
document
PdfDocumentthe target document of the new font
colorized
boolindicates 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
PdfDocumentthe target document of the new font.
fontName
stringthe PostScript name of the font, shall not be null or empty.
fontFamily
stringa preferred font family name.
colorized
boolindicates 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
stringthe 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
stringthe 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
RegisterDirectory(string)
Registers all the fonts in a directory.
public static int RegisterDirectory(string dirPath)
Parameters
dirPath
stringthe 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
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.