iText 7 7.1.8 API
iText.Kernel.Font.PdfFontFactory Class Reference

This class provides helpful methods for creating fonts ready to be used in a iText.Kernel.Pdf.PdfDocument More...

Static Public Member Functions

static PdfFont  CreateFont ()
  Creates a new instance of default font, namely iText.IO.Font.Constants.StandardFonts.HELVETICA standard font with iText.IO.Font.PdfEncodings.WINANSI encoding. Note, if you want to reuse the same instance of default font, you may use iText.Kernel.Pdf.PdfDocument.GetDefaultFont() More...
 
static PdfFont  CreateFont (PdfDictionary fontDictionary)
  Creates a PdfFont by already existing font dictionary. More...
 
static PdfFont  CreateFont (String fontProgram, String encoding, PdfDocument cacheTo)
 
Exceptions
System.IO.IOException

 
static PdfFont  CreateFont (String fontProgram)
  Creates a PdfFont instance by the path of the font program file More...
 
static PdfFont  CreateFont (String fontProgram, String encoding)
  Creates a PdfFont instance by the path of the font program file and given encoding. More...
 
static PdfFont  CreateTtcFont (byte[] ttc, int ttcIndex, String encoding, bool embedded, bool cached)
  Creates a PdfFont instance from the TrueType Collection represented by its byte contents. More...
 
static PdfFont  CreateTtcFont (String ttc, int ttcIndex, String encoding, bool embedded, bool cached)
  Creates a PdfFont instance from the TrueType Collection given by the path to the .ttc file. More...
 
static PdfFont  CreateFont (String fontProgram, bool embedded)
  Created a PdfFont instance given the path to the font file. More...
 
static PdfFont  CreateFont (String fontProgram, String encoding, bool embedded)
  Created a PdfFont instance given the path to the font file. More...
 
static PdfFont  CreateFont (String fontProgram, String encoding, bool embedded, bool cached)
  Created a PdfFont instance given the path to the font file. More...
 
static PdfFont  CreateFont (FontProgram fontProgram, String encoding, bool embedded)
  Created a PdfFont instance given the given underlying iText.IO.Font.FontProgram instance. More...
 
static PdfFont  CreateFont (FontProgram fontProgram, String encoding)
  Created a PdfFont instance given the given underlying iText.IO.Font.FontProgram instance. More...
 
static PdfFont  CreateFont (FontProgram fontProgram)
  Created a PdfFont instance given the given underlying iText.IO.Font.FontProgram instance. More...
 
static PdfFont  CreateFont (byte[] fontProgram, String encoding)
  Created a PdfFont instance by the bytes of the underlying font program. More...
 
static PdfFont  CreateFont (byte[] fontProgram, bool embedded)
  Created a PdfFont instance by the bytes of the underlying font program. More...
 
static PdfFont  CreateFont (byte[] fontProgram, String encoding, bool embedded)
  Created a PdfFont instance by the bytes of the underlying font program. More...
 
static PdfFont  CreateFont (byte[] fontProgram, String encoding, bool embedded, bool cached)
  Created a PdfFont instance by the bytes of the underlying font program. More...
 
static PdfType3Font  CreateType3Font (PdfDocument document, bool colorized)
  Creates a new instance of PdfType3Font More...
 
static PdfType3Font  CreateType3Font (PdfDocument document, String fontName, String fontFamily, bool colorized)
  Creates a new instance of PdfType3Font More...
 
static PdfFont  CreateRegisteredFont (String fontName, String encoding, bool embedded, int style, bool cached)
  Creates PdfFont based on registered iText.IO.Font.FontProgram 's. More...
 
static PdfFont  CreateRegisteredFont (String fontName, String encoding, bool embedded, bool cached)
  Creates PdfFont based on registered iText.IO.Font.FontProgram 's. More...
 
static PdfFont  CreateRegisteredFont (String fontName, String encoding, bool embedded)
  Creates PdfFont based on registered iText.IO.Font.FontProgram 's. More...
 
static PdfFont  CreateRegisteredFont (String fontName, String encoding, bool embedded, int style)
  Creates PdfFont based on registered iText.IO.Font.FontProgram 's. More...
 
static PdfFont  CreateRegisteredFont (String fontName, String encoding)
  Creates PdfFont based on registered iText.IO.Font.FontProgram 's. More...
 
static PdfFont  CreateRegisteredFont (String fontName)
  Creates PdfFont based on registered iText.IO.Font.FontProgram 's. More...
 
static void  RegisterFamily (String familyName, String fullName, String path)
  Register a font by giving explicitly the font family and name. More...
 
static void  Register (String path)
  Registers a .ttf, .otf, .afm, .pfm, or a .ttc font file. More...
 
static void  Register (String path, String alias)
  Register a font file and use an alias for the font contained in it. More...
 
static int  RegisterDirectory (String dirPath)
  Registers all the fonts in a directory. More...
 
static int  RegisterSystemDirectories ()
  Register fonts in some probable directories. More...
 
static ICollection< String >  GetRegisteredFonts ()
  Gets a set of registered font names. More...
 
static ICollection< String >  GetRegisteredFamilies ()
  Gets a set of registered font families. More...
 
static bool  IsRegistered (String fontName)
  Checks if a certain font is registered. More...
 

Detailed Description

This class provides helpful methods for creating fonts ready to be used in a iText.Kernel.Pdf.PdfDocument

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

Member Function Documentation

◆ CreateFont() [1/14]

static PdfFont iText.Kernel.Font.PdfFontFactory.CreateFont ( )
inlinestatic

Creates a new instance of default font, namely iText.IO.Font.Constants.StandardFonts.HELVETICA standard font with iText.IO.Font.PdfEncodings.WINANSI encoding. Note, if you want to reuse the same instance of default font, you may use iText.Kernel.Pdf.PdfDocument.GetDefaultFont()

Returns
created font
Exceptions
System.IO.IOException if error occurred while creating the font, e.g. metrics loading failure

◆ CreateFont() [2/14]

static PdfFont iText.Kernel.Font.PdfFontFactory.CreateFont ( byte[]  fontProgram,
bool  embedded 
)
inlinestatic

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

Parameters
fontProgram the bytes of the underlying font program
embedded indicates whether the font is to be embedded into the target document
Returns
created PdfFont instance
Exceptions
System.IO.IOException signals that an I/O exception has occurred.

◆ CreateFont() [3/14]

static PdfFont iText.Kernel.Font.PdfFontFactory.CreateFont ( byte[]  fontProgram,
String  encoding 
)
inlinestatic

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

Parameters
fontProgram the bytes of the underlying font program
encoding the encoding of the font to be created. See iText.IO.Font.PdfEncodings
Returns
created PdfFont instance
Exceptions
System.IO.IOException signals that an I/O exception has occurred.

◆ CreateFont() [4/14]

static PdfFont iText.Kernel.Font.PdfFontFactory.CreateFont ( byte[]  fontProgram,
String  encoding,
bool  embedded 
)
inlinestatic

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

Parameters
fontProgram the bytes of the underlying font program
encoding the encoding of the font to be created. See iText.IO.Font.PdfEncodings
embedded indicates whether the font is to be embedded into the target document
Returns
created PdfFont instance
Exceptions
System.IO.IOException signals that an I/O exception has occurred.

◆ CreateFont() [5/14]

static PdfFont iText.Kernel.Font.PdfFontFactory.CreateFont ( byte[]  fontProgram,
String  encoding,
bool  embedded,
bool  cached 
)
inlinestatic

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

Parameters
fontProgram the bytes of the underlying font program
encoding the encoding of the font to be created. See iText.IO.Font.PdfEncodings
embedded indicates whether the font is to be embedded into the target document
cached indicates whether the font will be cached
Returns
created PdfFont instance
Exceptions
System.IO.IOException signals that an I/O exception has occurred.

◆ CreateFont() [6/14]

static PdfFont iText.Kernel.Font.PdfFontFactory.CreateFont ( FontProgram  fontProgram )
inlinestatic

Created a PdfFont instance given the given underlying iText.IO.Font.FontProgram instance.

Parameters
fontProgram the font program of the PdfFont instance to be created
Returns
created PdfFont instance

◆ CreateFont() [7/14]

static PdfFont iText.Kernel.Font.PdfFontFactory.CreateFont ( FontProgram  fontProgram,
String  encoding 
)
inlinestatic

Created a PdfFont instance given the given underlying iText.IO.Font.FontProgram instance.

Parameters
fontProgram the font program of the PdfFont instance to be created
encoding the encoding of the font to be created. See iText.IO.Font.PdfEncodings
Returns
created PdfFont instance

◆ CreateFont() [8/14]

static PdfFont iText.Kernel.Font.PdfFontFactory.CreateFont ( FontProgram  fontProgram,
String  encoding,
bool  embedded 
)
inlinestatic

Created a PdfFont instance given the given underlying iText.IO.Font.FontProgram instance.

Parameters
fontProgram the font program of the PdfFont instance to be created
encoding the encoding of the font to be created. See iText.IO.Font.PdfEncodings
embedded indicates whether the font is to be embedded into the target document
Returns
created PdfFont instance

◆ CreateFont() [9/14]

static PdfFont iText.Kernel.Font.PdfFontFactory.CreateFont ( PdfDictionary  fontDictionary )
inlinestatic

Creates a PdfFont by already existing font dictionary.

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

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

Parameters
fontDictionary the font dictionary to create the font from
Returns
created PdfFont instance

◆ CreateFont() [10/14]

static PdfFont iText.Kernel.Font.PdfFontFactory.CreateFont ( String  fontProgram )
inlinestatic

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

Parameters
fontProgram the path of the font program file
Returns
created PdfFont instance
Exceptions
System.IO.IOException exception is thrown in case an I/O error occurs when reading the file

◆ CreateFont() [11/14]

static PdfFont iText.Kernel.Font.PdfFontFactory.CreateFont ( String  fontProgram,
bool  embedded 
)
inlinestatic

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

Parameters
fontProgram the font program file
embedded indicates whether the font is to be embedded into the target document
Returns
created PdfFont instance
Exceptions
System.IO.IOException in case the file is not found or the contents of the font file is mal-formed

◆ CreateFont() [12/14]

static PdfFont iText.Kernel.Font.PdfFontFactory.CreateFont ( String  fontProgram,
String  encoding 
)
inlinestatic

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

Parameters
fontProgram the path of the font program file
encoding the font encoding. See iText.IO.Font.PdfEncodings
Returns
created PdfFont instance
Exceptions
System.IO.IOException exception is thrown in case an I/O error occurs when reading the file

◆ CreateFont() [13/14]

static PdfFont iText.Kernel.Font.PdfFontFactory.CreateFont ( String  fontProgram,
String  encoding,
bool  embedded 
)
inlinestatic

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

Parameters
fontProgram the font program file
encoding the encoding of the font to be created. See iText.IO.Font.PdfEncodings
embedded indicates whether the font is to be embedded into the target document
Returns
created PdfFont instance
Exceptions
System.IO.IOException in case the file is not found or the contents of the font file is mal-formed

◆ CreateFont() [14/14]

static PdfFont iText.Kernel.Font.PdfFontFactory.CreateFont ( String  fontProgram,
String  encoding,
bool  embedded,
bool  cached 
)
inlinestatic

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

Parameters
fontProgram the font program file
encoding the encoding of the font to be created. See iText.IO.Font.PdfEncodings
embedded indicates whether the font is to be embedded into the target document
cached indicates whether the font will be cached
Returns
created PdfFont instance
Exceptions
System.IO.IOException in case the file is not found or the contents of the font file is mal-formed

◆ CreateRegisteredFont() [1/6]

static PdfFont iText.Kernel.Font.PdfFontFactory.CreateRegisteredFont ( String  fontName )
inlinestatic

Creates PdfFont based on registered iText.IO.Font.FontProgram 's.

Parameters
fontName Path to font file or Standard font name
Exceptions
System.IO.IOException exception is thrown in case an I/O error occurs when reading the file
See also
Register(System.String), Register(System.String, System.String), RegisterFamily(System.String, System.String, System.String), RegisterDirectory(System.String), RegisterSystemDirectories(), GetRegisteredFamilies(), GetRegisteredFonts()

◆ CreateRegisteredFont() [2/6]

static PdfFont iText.Kernel.Font.PdfFontFactory.CreateRegisteredFont ( String  fontName,
String  encoding 
)
inlinestatic

Creates PdfFont based on registered iText.IO.Font.FontProgram 's.

Parameters
fontName Path to font file or Standard font name
encoding Font encoding from iText.IO.Font.PdfEncodings
Exceptions
System.IO.IOException exception is thrown in case an I/O error occurs when reading the file
See also
Register(System.String), Register(System.String, System.String), RegisterFamily(System.String, System.String, System.String), RegisterDirectory(System.String), RegisterSystemDirectories(), GetRegisteredFamilies(), GetRegisteredFonts()

◆ CreateRegisteredFont() [3/6]

static PdfFont iText.Kernel.Font.PdfFontFactory.CreateRegisteredFont ( String  fontName,
String  encoding,
bool  embedded 
)
inlinestatic

Creates PdfFont based on registered iText.IO.Font.FontProgram 's.

Parameters
fontName Path to font file or Standard font name
encoding Font encoding from iText.IO.Font.PdfEncodings
embedded if true font will be embedded. Note, standard font won't be embedded in any case.
Exceptions
System.IO.IOException exception is thrown in case an I/O error occurs when reading the file
See also
Register(System.String), Register(System.String, System.String), RegisterFamily(System.String, System.String, System.String), RegisterDirectory(System.String), RegisterSystemDirectories(), GetRegisteredFamilies(), GetRegisteredFonts()

◆ CreateRegisteredFont() [4/6]

static PdfFont iText.Kernel.Font.PdfFontFactory.CreateRegisteredFont ( String  fontName,
String  encoding,
bool  embedded,
bool  cached 
)
inlinestatic

Creates PdfFont based on registered iText.IO.Font.FontProgram 's.

Parameters
fontName Path to font file or Standard font name
encoding Font encoding from iText.IO.Font.PdfEncodings
embedded if true font will be embedded. Note, standard font won't be embedded in any case.
cached If true font will be cached for another PdfDocument
Exceptions
System.IO.IOException exception is thrown in case an I/O error occurs when reading the file
See also
Register(System.String), Register(System.String, System.String), RegisterFamily(System.String, System.String, System.String), RegisterDirectory(System.String), RegisterSystemDirectories(), GetRegisteredFamilies(), GetRegisteredFonts()

◆ CreateRegisteredFont() [5/6]

static PdfFont iText.Kernel.Font.PdfFontFactory.CreateRegisteredFont ( String  fontName,
String  encoding,
bool  embedded,
int  style 
)
inlinestatic

Creates PdfFont based on registered iText.IO.Font.FontProgram 's.

Parameters
fontName Path to font file or Standard font name
encoding Font encoding from iText.IO.Font.PdfEncodings
embedded if true font will be embedded. Note, standard font won't be embedded in any case.
style Font style from iText.IO.Font.Constants.FontStyles
Exceptions
System.IO.IOException exception is thrown in case an I/O error occurs when reading the file
See also
Register(System.String), Register(System.String, System.String), RegisterFamily(System.String, System.String, System.String), RegisterDirectory(System.String), RegisterSystemDirectories(), GetRegisteredFamilies(), GetRegisteredFonts()

◆ CreateRegisteredFont() [6/6]

static PdfFont iText.Kernel.Font.PdfFontFactory.CreateRegisteredFont ( String  fontName,
String  encoding,
bool  embedded,
int  style,
bool  cached 
)
inlinestatic

Creates PdfFont based on registered iText.IO.Font.FontProgram 's.

Parameters
fontName Path to font file or Standard font name
encoding Font encoding from iText.IO.Font.PdfEncodings
embedded if true font will be embedded. Note, standard font won't be embedded in any case.
style Font style from iText.IO.Font.Constants.FontStyles
cached If true font will be cached for another PdfDocument
Exceptions
System.IO.IOException exception is thrown in case an I/O error occurs when reading the file
See also
Register(System.String), Register(System.String, System.String), RegisterFamily(System.String, System.String, System.String), RegisterDirectory(System.String), RegisterSystemDirectories(), GetRegisteredFamilies(), GetRegisteredFonts()

◆ CreateTtcFont() [1/2]

static PdfFont iText.Kernel.Font.PdfFontFactory.CreateTtcFont ( byte[]  ttc,
int  ttcIndex,
String  encoding,
bool  embedded,
bool  cached 
)
inlinestatic

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

Parameters
ttc the byte contents of the TrueType Collection
ttcIndex the index of the font in the collection, zero-based
encoding the encoding of the font to be created. See iText.IO.Font.PdfEncodings
embedded indicates whether the font is to be embedded into the target document
cached indicates whether the font will be cached
Returns
created PdfFont instance
Exceptions
System.IO.IOException in case the contents of the TrueType Collection is mal-formed or an error occurred during reading the font

◆ CreateTtcFont() [2/2]

static PdfFont iText.Kernel.Font.PdfFontFactory.CreateTtcFont ( String  ttc,
int  ttcIndex,
String  encoding,
bool  embedded,
bool  cached 
)
inlinestatic

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

Parameters
ttc the path of the .ttc file
ttcIndex the index of the font in the collection, zero-based
encoding the encoding of the font to be created. See iText.IO.Font.PdfEncodings
embedded indicates whether the font is to be embedded into the target document
cached indicates whether the font will be cached
Returns
created PdfFont instance
Exceptions
System.IO.IOException in case the file is not found, contents of the TrueType Collection is mal-formed or an error occurred during reading the font

◆ CreateType3Font() [1/2]

static PdfType3Font iText.Kernel.Font.PdfFontFactory.CreateType3Font ( PdfDocument  document,
bool  colorized 
)
inlinestatic

Creates a new instance of PdfType3Font

Parameters
document the target document of the new font
colorized indicates whether the font will be colorized
Returns
created font

◆ CreateType3Font() [2/2]

static PdfType3Font iText.Kernel.Font.PdfFontFactory.CreateType3Font ( PdfDocument  document,
String  fontName,
String  fontFamily,
bool  colorized 
)
inlinestatic

Creates a new instance of PdfType3Font

Parameters
document the target document of the new font.
fontName the PostScript name of the font, shall not be null or empty.
fontFamily a preferred font family name.
colorized indicates whether the font will be colorized
Returns
created font.

◆ GetRegisteredFamilies()

static ICollection iText.Kernel.Font.PdfFontFactory.GetRegisteredFamilies ( )
inlinestatic

Gets a set of registered font families.

Returns
a set of registered font families

◆ GetRegisteredFonts()

static ICollection iText.Kernel.Font.PdfFontFactory.GetRegisteredFonts ( )
inlinestatic

Gets a set of registered font names.

Returns
a set of registered fonts

◆ IsRegistered()

static bool iText.Kernel.Font.PdfFontFactory.IsRegistered ( String  fontName )
inlinestatic

Checks if a certain font is registered.

Parameters
fontName the name of the font that has to be checked.
Returns
true
if the font is found,
false
otherwise

◆ Register() [1/2]

static void iText.Kernel.Font.PdfFontFactory.Register ( String  path )
inlinestatic

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

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.

Parameters
path the path to a font file

◆ Register() [2/2]

static void iText.Kernel.Font.PdfFontFactory.Register ( String  path,
String  alias 
)
inlinestatic

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

Parameters
path the path to a font file
alias the alias you want to use for the font

◆ RegisterDirectory()

static int iText.Kernel.Font.PdfFontFactory.RegisterDirectory ( String  dirPath )
inlinestatic

Registers all the fonts in a directory.

Parameters
dirPath the directory path to be registered as a font directory path
Returns
the number of fonts registered

◆ RegisterFamily()

static void iText.Kernel.Font.PdfFontFactory.RegisterFamily ( String  familyName,
String  fullName,
String  path 
)
inlinestatic

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

Parameters
familyName the font family
fullName the font name
path the font path

◆ RegisterSystemDirectories()

static int iText.Kernel.Font.PdfFontFactory.RegisterSystemDirectories ( )
inlinestatic

Register fonts in some probable directories.

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

Returns
the number of fonts registered