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 failurepublic 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 fromPdfFont
instancepublic 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 fileencoding
- the font encoding. See PdfEncodings
cacheTo
- the PdfDocument
to cache the fontPdfFont
instanceIOException
- exception is thrown in case an I/O error occurs when reading the filepublic 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 fileencoding
- the font encoding. See PdfEncodings
embeddingStrategy
- the PdfFontFactory.EmbeddingStrategy
which will define whether the font will be embeddedcacheTo
- the PdfDocument
to cache the fontPdfFont
instanceIOException
- exception is thrown in case an I/O error occurs when reading the filepublic static PdfFont createFont(String fontProgram) throws IOException
PdfFont
instance by the path of the font program filefontProgram
- the path of the font program filePdfFont
instanceIOException
- exception is thrown in case an I/O error occurs when reading the filepublic 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 fileencoding
- the font encoding. See PdfEncodings
PdfFont
instanceIOException
- exception is thrown in case an I/O error occurs when reading the filepublic static PdfFont createFont(String fontProgram, PdfFontFactory.EmbeddingStrategy embeddingStrategy) throws IOException
PdfFont
instance given the path to the font file.fontProgram
- the font program fileembeddingStrategy
- the PdfFontFactory.EmbeddingStrategy
which will define whether the font will be embeddedPdfFont
instanceIOException
- in case the file is not found or the contents of the font file is mal-formedpublic 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 fileencoding
- the encoding of the font to be created. See PdfEncodings
embeddingStrategy
- the PdfFontFactory.EmbeddingStrategy
which will define whether the font will be embeddedPdfFont
instanceIOException
- in case the file is not found or the contents of the font file is mal-formedpublic 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 fileencoding
- the encoding of the font to be created. See PdfEncodings
embeddingStrategy
- the PdfFontFactory.EmbeddingStrategy
which will define whether the font will be embeddedcached
- indicates whether the font will be cachedPdfFont
instanceIOException
- in case the file is not found or the contents of the font file is mal-formedpublic 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 createdencoding
- the encoding of the font to be created. See PdfEncodings
embeddingStrategy
- the PdfFontFactory.EmbeddingStrategy
which will define whether the font will be embeddedPdfFont
instancepublic 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 createdencoding
- the encoding of the font to be created. See PdfEncodings
PdfFont
instancepublic 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 programencoding
- the encoding of the font to be created. See PdfEncodings
PdfFont
instanceIOException
- 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 programembeddingStrategy
- the PdfFontFactory.EmbeddingStrategy
which will define whether the font will be embeddedPdfFont
instanceIOException
- 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 programencoding
- the encoding of the font to be created. See PdfEncodings
embeddingStrategy
- the PdfFontFactory.EmbeddingStrategy
which will define whether the font will be embeddedPdfFont
instanceIOException
- 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 programencoding
- the encoding of the font to be created. See PdfEncodings
embeddingStrategy
- the PdfFontFactory.EmbeddingStrategy
which will define whether the font will be embeddedcached
- indicates whether the font will be cachedPdfFont
instanceIOException
- 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 CollectionttcIndex
- the index of the font in the collection, zero-basedencoding
- the encoding of the font to be created. See PdfEncodings
embeddingStrategy
- the PdfFontFactory.EmbeddingStrategy
which will define whether the font will be embeddedcached
- indicates whether the font will be cachedPdfFont
instanceIOException
- in case the contents of the TrueType Collection is mal-formed or an error
occurred during reading the fontpublic 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 filettcIndex
- the index of the font in the collection, zero-basedencoding
- the encoding of the font to be created. See PdfEncodings
embeddingStrategy
- the PdfFontFactory.EmbeddingStrategy
which will define whether the font will be embeddedcached
- indicates whether the font will be cachedPdfFont
instanceIOException
- in case the file is not found, contents of the TrueType Collection is mal-formed
or an error occurred during reading the fontpublic static PdfType3Font createType3Font(PdfDocument document, boolean colorized)
PdfType3Font
document
- the target document of the new fontcolorized
- indicates whether the font will be colorizedpublic 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 colorizedpublic 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 nameencoding
- 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 PdfDocumentFontProgram
was found among registered, otherwise null.IOException
- exception is thrown in case an I/O error occurs when reading the fileregister(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 nameencoding
- 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 PdfDocumentFontProgram
was found among registered, otherwise null.IOException
- exception is thrown in case an I/O error occurs when reading the fileregister(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 nameencoding
- 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 fileregister(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 nameencoding
- 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 fileregister(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 nameencoding
- 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 fileregister(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 nameFontProgram
was found among registered, otherwise null.IOException
- exception is thrown in case an I/O error occurs when reading the fileregister(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 familyfullName
- the font namepath
- the font pathpublic static void register(String path)
path
- the path to a font filepublic static void register(String path, String alias)
path
- the path to a font filealias
- the alias you want to use for the fontpublic static int registerDirectory(String dirPath)
dirPath
- the directory path to be registered as a font directory pathpublic 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
otherwiseCopyright © 1998–2023 Apryse Group NV. All rights reserved.