public final class PdfFontFactory extends Object
PdfDocument
Note, just created PdfFont
is almost empty until it will be flushed, because it is impossible to fulfill font data until flush.
Modifier and Type | Class and Description |
---|---|
static class |
PdfFontFactory.EmbeddingStrategy
Enum values for font embedding strategies.
|
Constructor and Description |
---|
PdfFontFactory() |
Modifier and Type | Method and Description |
---|---|
static PdfFont |
createFont()
Creates a new instance of default font, namely StandardFonts.HELVETICA standard font with PdfEncodings.WINANSI encoding.
|
static PdfFont |
createFont(byte[] fontProgram, PdfFontFactory.EmbeddingStrategy embeddingStrategy)
Created a PdfFont instance by the bytes of the underlying font program.
|
static PdfFont |
createFont(byte[] fontProgram, String encoding)
Created a PdfFont instance by the bytes of the underlying font program.
|
static PdfFont |
createFont(byte[] fontProgram, String encoding, PdfFontFactory.EmbeddingStrategy embeddingStrategy)
Created a PdfFont instance by the bytes of the underlying font program.
|
static PdfFont |
createFont(byte[] fontProgram, String encoding, PdfFontFactory.EmbeddingStrategy embeddingStrategy, boolean cached)
Created a PdfFont instance by the bytes of the underlying font program.
|
static PdfFont |
createFont(FontProgram fontProgram)
Created a PdfFont instance given the given underlying FontProgram instance.
|
static PdfFont |
createFont(FontProgram fontProgram, String encoding)
Created a PdfFont instance given the given underlying FontProgram instance.
|
static PdfFont |
createFont(FontProgram fontProgram, String encoding, PdfFontFactory.EmbeddingStrategy embeddingStrategy)
Created a PdfFont instance given the given underlying FontProgram instance.
|
static PdfFont |
createFont(PdfDictionary fontDictionary)
Creates a PdfFont by already existing font dictionary.
|
static PdfFont |
createFont(String fontProgram)
Creates a PdfFont instance by the path of the font program file
|
static PdfFont |
createFont(String fontProgram, PdfFontFactory.EmbeddingStrategy embeddingStrategy)
Created a PdfFont instance given the path to the font file.
|
static PdfFont |
createFont(String fontProgram, String encoding)
Creates a PdfFont instance by the path of the font program file and given encoding.
|
static PdfFont |
createFont(String fontProgram, String encoding, PdfDocument cacheTo)
Creates a PdfFont instance by the path of the font program file and given encoding and place it inside the PdfDocument .
|
static PdfFont |
createFont(String fontProgram, String encoding, PdfFontFactory.EmbeddingStrategy embeddingStrategy)
Created a PdfFont instance given the path to the font file.
|
static PdfFont |
createFont(String fontProgram, String encoding, PdfFontFactory.EmbeddingStrategy embeddingStrategy, boolean cached)
Created a PdfFont instance given the path to the font file.
|
static PdfFont |
createFont(String fontProgram, String encoding, PdfFontFactory.EmbeddingStrategy embeddingStrategy, PdfDocument cacheTo)
Creates a PdfFont instance by the path of the font program file and given encoding and place it inside the PdfDocument .
|
static PdfFont |
createRegisteredFont(String fontName)
Creates PdfFont based on registered FontProgram 's.
|
static PdfFont |
createRegisteredFont(String fontName, String encoding)
Creates PdfFont based on registered FontProgram 's.
|
static PdfFont |
createRegisteredFont(String fontName, String encoding, PdfFontFactory.EmbeddingStrategy embeddingStrategy)
Creates PdfFont based on registered FontProgram 's.
|
static PdfFont |
createRegisteredFont(String fontName, String encoding, PdfFontFactory.EmbeddingStrategy embeddingStrategy, boolean cached)
Creates PdfFont based on registered FontProgram 's.
|
static PdfFont |
createRegisteredFont(String fontName, String encoding, PdfFontFactory.EmbeddingStrategy embeddingStrategy, int style)
Creates PdfFont based on registered FontProgram 's.
|
static PdfFont |
createRegisteredFont(String fontName, String encoding, PdfFontFactory.EmbeddingStrategy embeddingStrategy, int style, boolean cached)
Creates PdfFont based on registered FontProgram 's.
|
static PdfFont |
createTtcFont(byte[] ttc, int ttcIndex, String encoding, PdfFontFactory.EmbeddingStrategy embeddingStrategy, boolean cached)
Creates a PdfFont instance from the TrueType Collection represented by its byte contents.
|
static PdfFont |
createTtcFont(String ttc, int ttcIndex, String encoding, PdfFontFactory.EmbeddingStrategy embeddingStrategy, boolean cached)
Creates a PdfFont instance from the TrueType Collection given by the path to the .ttc file.
|
static PdfType3Font |
createType3Font(PdfDocument document, boolean colorized)
Creates a new instance of PdfType3Font
|
static PdfType3Font |
createType3Font(PdfDocument document, String fontName, String fontFamily, boolean colorized)
Creates a new instance of PdfType3Font
|
static Set<String> |
getRegisteredFamilies()
Gets a set of registered font families.
|
static Set<String> |
getRegisteredFonts()
Gets a set of registered font names.
|
static boolean |
isRegistered(String fontName)
Checks if a certain font is registered.
|
static void |
register(String path)
Registers a .ttf, .otf, .afm, .pfm, or a .ttc font file.
|
static void |
register(String path, String alias)
Register a font file and use an alias for the font contained in it.
|
static int |
registerDirectory(String dirPath)
Registers all the fonts in a directory.
|
static void |
registerFamily(String familyName, String fullName, String path)
Register a font by giving explicitly the font family and name.
|
static int |
registerSystemDirectories()
Register fonts in some probable directories.
|
public static PdfFont createFont() throws IOException
StandardFonts.HELVETICA
standard font with PdfEncodings.WINANSI
encoding. Note, if you want to reuse the same instance of default font, you may use PdfDocument.getDefaultFont()
.
IOException
- if error occurred while creating the font, e.g. metrics loading failure
public static PdfFont createFont(PdfDictionary fontDictionary)
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.
PdfDocument.getFont(com.itextpdf.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.
fontDictionary
- the font dictionary to create the font from
PdfFont
instance
public static PdfFont createFont(String fontProgram, String encoding, PdfDocument cacheTo) throws IOException
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. PdfFontFactory.EmbeddingStrategy.PREFER_EMBEDDED
will be used as embedding strategy.
fontProgram
- the path of the font program file
encoding
- the font encoding. See PdfEncodings
cacheTo
- the PdfDocument
to cache the font
PdfFont
instance
IOException
- exception is thrown in case an I/O error occurs when reading the file
public static PdfFont createFont(String fontProgram, String encoding, PdfFontFactory.EmbeddingStrategy embeddingStrategy, PdfDocument cacheTo) throws IOException
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.
fontProgram
- the path of the font program file
encoding
- the font encoding. See PdfEncodings
embeddingStrategy
- the PdfFontFactory.EmbeddingStrategy
which will define whether the font will be embedded
cacheTo
- the PdfDocument
to cache the font
PdfFont
instance
IOException
- exception is thrown in case an I/O error occurs when reading the file
public static PdfFont createFont(String fontProgram) throws IOException
PdfFont
instance by the path of the font program file
fontProgram
- the path of the font program file
PdfFont
instance
IOException
- exception is thrown in case an I/O error occurs when reading the file
public static PdfFont createFont(String fontProgram, String encoding) throws IOException
PdfFont
instance by the path of the font program file and given encoding.
fontProgram
- the path of the font program file
encoding
- the font encoding. See PdfEncodings
PdfFont
instance
IOException
- exception is thrown in case an I/O error occurs when reading the file
public static PdfFont createFont(String fontProgram, PdfFontFactory.EmbeddingStrategy embeddingStrategy) throws IOException
PdfFont
instance given the path to the font file.
fontProgram
- the font program file
embeddingStrategy
- the PdfFontFactory.EmbeddingStrategy
which will define whether the font will be embedded
PdfFont
instance
IOException
- in case the file is not found or the contents of the font file is mal-formed
public static PdfFont createFont(String fontProgram, String encoding, PdfFontFactory.EmbeddingStrategy embeddingStrategy) throws IOException
PdfFont
instance given the path to the font file.
fontProgram
- the font program file
encoding
- the encoding of the font to be created. See PdfEncodings
embeddingStrategy
- the PdfFontFactory.EmbeddingStrategy
which will define whether the font will be embedded
PdfFont
instance
IOException
- in case the file is not found or the contents of the font file is mal-formed
public static PdfFont createFont(String fontProgram, String encoding, PdfFontFactory.EmbeddingStrategy embeddingStrategy, boolean cached) throws IOException
PdfFont
instance given the path to the font file.
fontProgram
- the font program file
encoding
- the encoding of the font to be created. See PdfEncodings
embeddingStrategy
- the PdfFontFactory.EmbeddingStrategy
which will define whether the font will be embedded
cached
- indicates whether the font will be cached
PdfFont
instance
IOException
- in case the file is not found or the contents of the font file is mal-formed
public static PdfFont createFont(FontProgram fontProgram, String encoding, PdfFontFactory.EmbeddingStrategy embeddingStrategy)
PdfFont
instance given the given underlying FontProgram
instance.
fontProgram
- the font program of the PdfFont
instance to be created
encoding
- the encoding of the font to be created. See PdfEncodings
embeddingStrategy
- the PdfFontFactory.EmbeddingStrategy
which will define whether the font will be embedded
PdfFont
instance
public static PdfFont createFont(FontProgram fontProgram, String encoding)
PdfFont
instance given the given underlying FontProgram
instance.
fontProgram
- the font program of the PdfFont
instance to be created
encoding
- the encoding of the font to be created. See PdfEncodings
PdfFont
instance
public static PdfFont createFont(FontProgram fontProgram)
PdfFont
instance given the given underlying FontProgram
instance.
public static PdfFont createFont(byte[] fontProgram, String encoding) throws IOException
PdfFont
instance by the bytes of the underlying font program.
fontProgram
- the bytes of the underlying font program
encoding
- the encoding of the font to be created. See PdfEncodings
PdfFont
instance
IOException
- signals that an I/O exception has occurred.
public static PdfFont createFont(byte[] fontProgram, PdfFontFactory.EmbeddingStrategy embeddingStrategy) throws IOException
PdfFont
instance by the bytes of the underlying font program.
fontProgram
- the bytes of the underlying font program
embeddingStrategy
- the PdfFontFactory.EmbeddingStrategy
which will define whether the font will be embedded
PdfFont
instance
IOException
- signals that an I/O exception has occurred.
public static PdfFont createFont(byte[] fontProgram, String encoding, PdfFontFactory.EmbeddingStrategy embeddingStrategy) throws IOException
PdfFont
instance by the bytes of the underlying font program.
fontProgram
- the bytes of the underlying font program
encoding
- the encoding of the font to be created. See PdfEncodings
embeddingStrategy
- the PdfFontFactory.EmbeddingStrategy
which will define whether the font will be embedded
PdfFont
instance
IOException
- signals that an I/O exception has occurred.
public static PdfFont createFont(byte[] fontProgram, String encoding, PdfFontFactory.EmbeddingStrategy embeddingStrategy, boolean cached) throws IOException
PdfFont
instance by the bytes of the underlying font program.
fontProgram
- the bytes of the underlying font program
encoding
- the encoding of the font to be created. See PdfEncodings
embeddingStrategy
- the PdfFontFactory.EmbeddingStrategy
which will define whether the font will be embedded
cached
- indicates whether the font will be cached
PdfFont
instance
IOException
- signals that an I/O exception has occurred.
public static PdfFont createTtcFont(byte[] ttc, int ttcIndex, String encoding, PdfFontFactory.EmbeddingStrategy embeddingStrategy, boolean cached) throws IOException
PdfFont
instance from the TrueType Collection represented by its byte contents.
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 PdfEncodings
embeddingStrategy
- the PdfFontFactory.EmbeddingStrategy
which will define whether the font will be embedded
cached
- indicates whether the font will be cached
PdfFont
instance
IOException
- in case the contents of the TrueType Collection is mal-formed or an error occurred during reading the font
public static PdfFont createTtcFont(String ttc, int ttcIndex, String encoding, PdfFontFactory.EmbeddingStrategy embeddingStrategy, boolean cached) throws IOException
PdfFont
instance from the TrueType Collection given by the path to the .ttc file.
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 PdfEncodings
embeddingStrategy
- the PdfFontFactory.EmbeddingStrategy
which will define whether the font will be embedded
cached
- indicates whether the font will be cached
PdfFont
instance
IOException
- in case the file is not found, contents of the TrueType Collection is mal-formed or an error occurred during reading the font
public static PdfType3Font createType3Font(PdfDocument document, boolean colorized)
PdfType3Font
document
- the target document of the new font
colorized
- indicates whether the font will be colorized
public static PdfType3Font createType3Font(PdfDocument document, String fontName, String fontFamily, boolean colorized)
PdfType3Font
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
public static PdfFont createRegisteredFont(String fontName, String encoding, PdfFontFactory.EmbeddingStrategy embeddingStrategy, int style, boolean cached) throws IOException
PdfFont
based on registered FontProgram
's. Required font program is expected to be previously registered by one of the register method from PdfFontFactory
.
fontName
- Path to font file or Standard font name
encoding
- Font encoding from PdfEncodings
.
embeddingStrategy
- the PdfFontFactory.EmbeddingStrategy
which will define whether the font will be embedded. Note, standard font won't be embedded in any case.
style
- Font style from FontStyles
.
cached
- If true font will be cached for another PdfDocument
FontProgram
was found among registered, otherwise null.
IOException
- exception is thrown in case an I/O error occurs when reading the file
register(String)
, register(String, String)
, registerFamily(String, String, String)
, registerDirectory(String)
, registerSystemDirectories()
, getRegisteredFamilies()
, getRegisteredFonts()
public static PdfFont createRegisteredFont(String fontName, String encoding, PdfFontFactory.EmbeddingStrategy embeddingStrategy, boolean cached) throws IOException
PdfFont
based on registered FontProgram
's. Required font program is expected to be previously registered by one of the register method from PdfFontFactory
.
fontName
- Path to font file or Standard font name
encoding
- Font encoding from PdfEncodings
.
embeddingStrategy
- the PdfFontFactory.EmbeddingStrategy
which will define whether the font will be embedded. Note, standard font won't be embedded in any case.
cached
- If true font will be cached for another PdfDocument
FontProgram
was found among registered, otherwise null.
IOException
- exception is thrown in case an I/O error occurs when reading the file
register(String)
, register(String, String)
, registerFamily(String, String, String)
, registerDirectory(String)
, registerSystemDirectories()
, getRegisteredFamilies()
, getRegisteredFonts()
public static PdfFont createRegisteredFont(String fontName, String encoding, PdfFontFactory.EmbeddingStrategy embeddingStrategy) throws IOException
PdfFont
based on registered FontProgram
's. Required font program is expected to be previously registered by one of the register method from PdfFontFactory
.
fontName
- Path to font file or Standard font name
encoding
- Font encoding from PdfEncodings
.
embeddingStrategy
- the PdfFontFactory.EmbeddingStrategy
which will define whether the font will be embedded. Note, standard font won't be embedded in any case.
FontProgram
was found among registered, otherwise null.
IOException
- exception is thrown in case an I/O error occurs when reading the file
register(String)
, register(String, String)
, registerFamily(String, String, String)
, registerDirectory(String)
, registerSystemDirectories()
, getRegisteredFamilies()
, getRegisteredFonts()
public static PdfFont createRegisteredFont(String fontName, String encoding, PdfFontFactory.EmbeddingStrategy embeddingStrategy, int style) throws IOException
PdfFont
based on registered FontProgram
's. Required font program is expected to be previously registered by one of the register method from PdfFontFactory
.
fontName
- Path to font file or Standard font name
encoding
- Font encoding from PdfEncodings
.
embeddingStrategy
- the PdfFontFactory.EmbeddingStrategy
which will define whether the font will be embedded. Note, standard font won't be embedded in any case.
style
- Font style from FontStyles
.
FontProgram
was found among registered, otherwise null.
IOException
- exception is thrown in case an I/O error occurs when reading the file
register(String)
, register(String, String)
, registerFamily(String, String, String)
, registerDirectory(String)
, registerSystemDirectories()
, getRegisteredFamilies()
, getRegisteredFonts()
public static PdfFont createRegisteredFont(String fontName, String encoding) throws IOException
PdfFont
based on registered FontProgram
's. Required font program is expected to be previously registered by one of the register method from PdfFontFactory
.
fontName
- Path to font file or Standard font name
encoding
- Font encoding from PdfEncodings
.
FontProgram
was found among registered, otherwise null.
IOException
- exception is thrown in case an I/O error occurs when reading the file
register(String)
, register(String, String)
, registerFamily(String, String, String)
, registerDirectory(String)
, registerSystemDirectories()
, getRegisteredFamilies()
, getRegisteredFonts()
public static PdfFont createRegisteredFont(String fontName) throws IOException
PdfFont
based on registered FontProgram
's. Required font program is expected to be previously registered by one of the register method from PdfFontFactory
.
fontName
- Path to font file or Standard font name
FontProgram
was found among registered, otherwise null.
IOException
- exception is thrown in case an I/O error occurs when reading the file
register(String)
, register(String, String)
, registerFamily(String, String, String)
, registerDirectory(String)
, registerSystemDirectories()
, getRegisteredFamilies()
, getRegisteredFonts()
public static void registerFamily(String familyName, String fullName, String path)
familyName
- the font family
fullName
- the font name
path
- the font path
public static void register(String path)
path
- the path to a font file
public static void register(String path, String alias)
path
- the path to a font file
alias
- the alias you want to use for the font
public static int registerDirectory(String dirPath)
dirPath
- the directory path to be registered as a font directory path
public static int registerSystemDirectories()
public static Set<String> getRegisteredFonts()
public static Set<String> getRegisteredFamilies()
public static boolean isRegistered(String fontName)
fontName
- the name of the font that has to be checked.
true
if the font is found, false
otherwise
Copyright © 1998–2022 iText Group NV. All rights reserved.