Top Description Fields Constructors Methods
org.apache.pdfbox.pdmodel.font

public Class PDType0Font

extends PDFont
implements PDVectorFont
Class Inheritance
All Implemented Interfaces
org.apache.pdfbox.pdmodel.font.PDVectorFont
Imports
java.awt.geom.GeneralPath, java.io.File, .IOException, .InputStream, java.util.HashSet, .List, .Set, org.apache.commons.logging.Log, .LogFactory, org.apache.fontbox.cmap.CMap, org.apache.fontbox.ttf.CmapLookup, .TTFParser, .TrueTypeFont, org.apache.fontbox.ttf.model.GsubData, org.apache.fontbox.util.BoundingBox, org.apache.pdfbox.cos.COSArray, .COSBase, .COSDictionary, .COSName, org.apache.pdfbox.io.RandomAccessRead, .RandomAccessReadBuffer, .RandomAccessReadBufferedFile, org.apache.pdfbox.pdmodel.PDDocument, org.apache.pdfbox.util.Matrix, .Vector

A Composite (Type 0) font.
Author
Ben Litchfield

Field Summary

Modifier and TypeField and Description
private CMap
private final CmapLookup
private CMap
private final PDCIDFont
private PDCIDFontType2Embedder
private final GsubData
private boolean
private boolean
private static final Log
private final Set<Integer>
private TrueTypeFont
Inherited from org.apache.pdfbox.pdmodel.font.PDFont:
DEFAULT_FONT_MATRIXdict

Constructor Summary

AccessConstructor and Description
public
PDType0Font(COSDictionary
The font dictionary according to the PDF specification.
fontDictionary
)

Constructor for reading a Type0 font from a PDF file.

private
PDType0Font(PDDocument document, TrueTypeFont ttf, boolean embedSubset, boolean
whether to close the ttf parameter after embedding. Must be true when the ttf parameter was created in the load() method, false when the ttf parameter was passed to the load() method.
closeTTF
,
boolean
whether to enable vertical substitutions.
vertical
)

Private.

Method Summary

Modifier and TypeMethod and Description
public void
public void
addToSubset(int
Unicode code point
codePoint
)

Implements abstract org.apache.pdfbox.pdmodel.font.PDFont.addToSubset.

Adds the given Unicode point to the subset.

public int

Returns:

CID for the given character code
codeToCID
(int
character code
code
)

Returns the CID for the given character code.

public int

Returns:

GID for the given character code
codeToGID
(int
character code
code
)

Returns the GID for the given character code.

protected byte[]
encode(int
Unicode code point.
unicode
)

Implements abstract org.apache.pdfbox.pdmodel.font.PDFont.encode.

Encodes the given Unicode code point for use in a PDF content stream.

public byte[]

Returns:

the encoded glyph ID
encodeGlyphId
(int
the ID of the glyph to be encoded
glyphId
)

Returns the encoded value for the given glyph ID.

private void
fetchCMapUCS2()

Fetches the corresponding UCS2 CMap if the font's CMap is predefined.

public float
public String

Returns:

the PostScript name of the font
getBaseFont
()

Returns the PostScript name of the font.

public BoundingBox
getBoundingBox()

Implements org.apache.pdfbox.pdmodel.font.PDFontLike.getBoundingBox.

Returns the font's bounding box.

public CMap

Returns:

the font's CMap
getCMap
()

Returns the font's CMap.

public CmapLookup

Returns:

the CMap lookup table if present
getCmapLookup
()

Returns the CMap lookup table if present.

public CMap

Returns:

the font's UCS2 CMap if present
getCMapUCS2
()

Returns the font's UCS2 CMap, only present this font uses a predefined CMap.

public PDCIDFont

Returns:

the descendant font
getDescendantFont
()

Returns the descendant font.

public Vector
getDisplacement(int
character code
code
)

Overrides org.apache.pdfbox.pdmodel.font.PDFont.getDisplacement.

Returns the displacement vector (w0, w1) in text space, for the given character.

public PDFontDescriptor
public Matrix
getFontMatrix()

Overrides org.apache.pdfbox.pdmodel.font.PDFont.getFontMatrix.

Implements org.apache.pdfbox.pdmodel.font.PDFontLike.getFontMatrix.

Returns the font matrix, which represents the transformation from glyph space to text space.

public GsubData

Returns:

the GSubData if present
getGsubData
()

Returns the GSubData if present.

public float
getHeight(int
character code
code
)

Implements org.apache.pdfbox.pdmodel.font.PDFontLike.getHeight.

Returns the height of the given character, in glyph space.

public String
getName()

Implements org.apache.pdfbox.pdmodel.font.PDFontLike.getName.

Returns the name of this font, either the PostScript "BaseName" or the Type 3 "Name".

public GeneralPath
getNormalizedPath(int
character code in a PDF. Not to be confused with unicode.
code
)

Implements org.apache.pdfbox.pdmodel.font.PDVectorFont.getNormalizedPath.

Returns the normalized glyph path for the given character code in a PDF.

public GeneralPath
getPath(int
character code in a PDF. Not to be confused with unicode.
code
)

Implements org.apache.pdfbox.pdmodel.font.PDVectorFont.getPath.

Returns the glyph path for the given character code.

public Vector
getPositionVector(int
character code
code
)

Overrides org.apache.pdfbox.pdmodel.font.PDFont.getPositionVector.

Implements org.apache.pdfbox.pdmodel.font.PDFontLike.getPositionVector.

Returns the position vector (v), in text space, for the given character.

protected float
getStandard14Width(int
character code
code
)

Implements abstract org.apache.pdfbox.pdmodel.font.PDFont.getStandard14Width.

Returns the glyph width from the AFM if this is a Standard 14 font.

public float
getWidth(int
character code
code
)

Overrides org.apache.pdfbox.pdmodel.font.PDFont.getWidth.

Implements org.apache.pdfbox.pdmodel.font.PDFontLike.getWidth.

Returns the advance width of the given character, in glyph space.

public float
getWidthFromFont(int
character code
code
)

Implements org.apache.pdfbox.pdmodel.font.PDFontLike.getWidthFromFont.

Returns the width of a glyph in the embedded font file.

public boolean
hasExplicitWidth(int
character code
code
)

Implements org.apache.pdfbox.pdmodel.font.PDFontLike.hasExplicitWidth.

Returns true if the Font dictionary specifies an explicit width for the given glyph.

public boolean
hasGlyph(int
character code in a PDF. Not to be confused with unicode.
code
)

Implements org.apache.pdfbox.pdmodel.font.PDVectorFont.hasGlyph.

Returns true if this font contains a glyph for the given character code in a PDF.

public boolean
isDamaged()

Implements org.apache.pdfbox.pdmodel.font.PDFontLike.isDamaged.

Returns true if the embedded font file is damaged.

public boolean
isEmbedded()

Implements org.apache.pdfbox.pdmodel.font.PDFontLike.isEmbedded.

Returns true if the font file is embedded in the PDF.

public boolean
isStandard14()

Overrides org.apache.pdfbox.pdmodel.font.PDFont.isStandard14.

Returns true if this font is one of the "Standard 14" fonts and receives special handling.

public boolean
isVertical()

Implements abstract org.apache.pdfbox.pdmodel.font.PDFont.isVertical.

Returns true if the font uses vertical writing mode.

public static PDType0Font

Returns:

A Type0 font with a CIDFontType2 descendant.
load
(PDDocument
The PDF document that will hold the embedded font.
doc
,
File
A TrueType font.
file
)

Loads a TTF to be embedded and subset into a document as a Type 0 font.

public static PDType0Font

Returns:

A Type0 font with a CIDFontType2 descendant.
load
(PDDocument
The PDF document that will hold the embedded font.
doc
,
InputStream
An input stream of a TrueType font. It will be closed before returning.
input
)

Loads a TTF to be embedded and subset into a document as a Type 0 font.

public static PDType0Font

Returns:

A Type0 font with a CIDFontType2 descendant.
load
(PDDocument
The PDF document that will hold the embedded font.
doc
,
InputStream
An input stream of a TrueType font. It will be closed before returning.
input
,
boolean
True if the font will be subset before embedding. Set this to false when creating a font for AcroForm.
embedSubset
)

Loads a TTF to be embedded into a document as a Type 0 font.

public static PDType0Font

Returns:

A Type0 font with a CIDFontType2 descendant.
load
(PDDocument
The PDF document that will hold the embedded font.
doc
,
RandomAccessRead
source of a TrueType font.
randomAccessRead
,
boolean
True if the font will be subset before embedding. Set this to false when creating a font for AcroForm.
embedSubset
,
boolean
whether to enable vertical substitutions.
vertical
)

Loads a TTF to be embedded into a document as a Type 0 font.

public static PDType0Font

Returns:

A Type0 font with a CIDFontType2 descendant.
load
(PDDocument
The PDF document that will hold the embedded font.
doc
,
TrueTypeFont
A TrueType font.
ttf
,
boolean
True if the font will be subset before embedding. Set this to false when creating a font for AcroForm.
embedSubset
)

Loads a TTF to be embedded into a document as a Type 0 font.

public static PDType0Font

Returns:

A Type0 font with a CIDFontType2 descendant.
loadVertical
(PDDocument
The PDF document that will hold the embedded font.
doc
,
File
A TrueType font.
file
)

Loads a TTF to be embedded into a document as a vertical Type 0 font.

public static PDType0Font

Returns:

A Type0 font with a CIDFontType2 descendant.
loadVertical
(PDDocument
The PDF document that will hold the embedded font.
doc
,
InputStream
A TrueType font.
input
)

Loads a TTF to be embedded into a document as a vertical Type 0 font.

public static PDType0Font

Returns:

A Type0 font with a CIDFontType2 descendant.
loadVertical
(PDDocument
The PDF document that will hold the embedded font.
doc
,
InputStream
A TrueType font.
input
,
boolean
True if the font will be subset before embedding
embedSubset
)

Loads a TTF to be embedded into a document as a vertical Type 0 font.

public static PDType0Font

Returns:

A Type0 font with a CIDFontType2 descendant.
loadVertical
(PDDocument
The PDF document that will hold the embedded font.
doc
,
TrueTypeFont
A TrueType font.
ttf
,
boolean
True if the font will be subset before embedding
embedSubset
)

Loads a TTF to be embedded into a document as a vertical Type 0 font.

public int
readCode(InputStream
string stream
in
)

Implements abstract org.apache.pdfbox.pdmodel.font.PDFont.readCode.

Reads a character code from a content stream string.

private void
readEncoding()

Reads the font's Encoding entry, which should be a CMap name/stream.

public void
subset()

Implements abstract org.apache.pdfbox.pdmodel.font.PDFont.subset.

Replaces this font with a subset containing only the given Unicode characters.

public String
toString()

Overrides org.apache.pdfbox.pdmodel.font.PDFont.toString.

Returns a string representation of the object.

public String
toUnicode(int
character code
code
)

Overrides org.apache.pdfbox.pdmodel.font.PDFont.toUnicode.

Returns the Unicode character sequence which corresponds to the given character code.

public boolean
willBeSubset()

Implements abstract org.apache.pdfbox.pdmodel.font.PDFont.willBeSubset.

Returns true if this font will be subset when embedded.

Inherited from org.apache.pdfbox.pdmodel.font.PDFont:
encodeequalsgetCOSObjectgetSpaceWidthgetStandard14AFMgetStringWidthgetSubTypegetToUnicodeCMapgetTypegetWidthshashCodereadCMapsetFontDescriptortoUnicode

Field Detail

cMapback to summary
private CMap cMap
cmapLookupback to summary
private final CmapLookup cmapLookup
cMapUCS2back to summary
private CMap cMapUCS2
descendantFontback to summary
private final PDCIDFont descendantFont
embedderback to summary
private PDCIDFontType2Embedder embedder
gsubDataback to summary
private final GsubData gsubData
isCMapPredefinedback to summary
private boolean isCMapPredefined
isDescendantCJKback to summary
private boolean isDescendantCJK
LOGback to summary
private static final Log LOG

Hides org.apache.pdfbox.pdmodel.font.PDFont.LOG.

noUnicodeback to summary
private final Set<Integer> noUnicode
ttfback to summary
private TrueTypeFont ttf

Constructor Detail

PDType0Fontback to summary
public PDType0Font(COSDictionary fontDictionary) throws IOException

Constructor for reading a Type0 font from a PDF file.

Parameters
fontDictionary:COSDictionary

The font dictionary according to the PDF specification.

Exceptions
IOException:
if the descendant font is missing.
PDType0Fontback to summary
private PDType0Font(PDDocument document, TrueTypeFont ttf, boolean embedSubset, boolean closeTTF, boolean vertical) throws IOException

Private. Creates a new PDType0Font font for embedding.

Parameters
closeTTF:boolean

whether to close the ttf parameter after embedding. Must be true when the ttf parameter was created in the load() method, false when the ttf parameter was passed to the load() method.

vertical:boolean

whether to enable vertical substitutions.

Method Detail

addGlyphsToSubsetback to summary
public void addGlyphsToSubset(Set<Integer> glyphIds)
addToSubsetback to summary
public void addToSubset(int codePoint)

Implements abstract org.apache.pdfbox.pdmodel.font.PDFont.addToSubset.

Doc from org.apache.pdfbox.pdmodel.font.PDFont.addToSubset.

Adds the given Unicode point to the subset.

Parameters
codePoint:int

Unicode code point

Annotations
@Override
codeToCIDback to summary
public int codeToCID(int code)

Returns the CID for the given character code. If not found then CID 0 is returned.

Parameters
code:int

character code

Returns:int

CID for the given character code

codeToGIDback to summary
public int codeToGID(int code) throws IOException

Returns the GID for the given character code.

Parameters
code:int

character code

Returns:int

GID for the given character code

Exceptions
IOException:
if the data could not be read
encodeback to summary
protected byte[] encode(int unicode) throws IOException

Implements abstract org.apache.pdfbox.pdmodel.font.PDFont.encode.

Doc from org.apache.pdfbox.pdmodel.font.PDFont.encode.

Encodes the given Unicode code point for use in a PDF content stream. Content streams use a multi-byte encoding with 1 to 4 bytes.

This method is called when embedding text in PDFs and when filling in fields.

Parameters
unicode:int

Unicode code point.

Returns:byte[]

Array of 1 to 4 PDF content stream bytes.

Annotations
@Override
Exceptions
IOException:
If the text could not be encoded.
encodeGlyphIdback to summary
public byte[] encodeGlyphId(int glyphId)

Returns the encoded value for the given glyph ID.

Parameters
glyphId:int

the ID of the glyph to be encoded

Returns:byte[]

the encoded glyph ID

fetchCMapUCS2back to summary
private void fetchCMapUCS2() throws IOException

Fetches the corresponding UCS2 CMap if the font's CMap is predefined.

getAverageFontWidthback to summary
public float getAverageFontWidth()

Overrides org.apache.pdfbox.pdmodel.font.PDFont.getAverageFontWidth.

Implements org.apache.pdfbox.pdmodel.font.PDFontLike.getAverageFontWidth.

Doc from org.apache.pdfbox.pdmodel.font.PDFont.getAverageFontWidth.

This will get the average font width for all characters.

Returns:float

The width is in 1000 unit of text space, ie 333 or 777

Annotations
@Override
getBaseFontback to summary
public String getBaseFont()

Returns the PostScript name of the font.

Returns:String

the PostScript name of the font

getBoundingBoxback to summary
public BoundingBox getBoundingBox() throws IOException

Implements org.apache.pdfbox.pdmodel.font.PDFontLike.getBoundingBox.

Doc from org.apache.pdfbox.pdmodel.font.PDFontLike.getBoundingBox.

Returns the font's bounding box.

Returns:BoundingBox

the bounding box

Annotations
@Override
Exceptions
IOException:
if the bounding box could not be read
getCMapback to summary
public CMap getCMap()

Returns the font's CMap.

Returns:CMap

the font's CMap

getCmapLookupback to summary
public CmapLookup getCmapLookup()

Returns the CMap lookup table if present.

Returns:CmapLookup

the CMap lookup table if present

getCMapUCS2back to summary
public CMap getCMapUCS2()

Returns the font's UCS2 CMap, only present this font uses a predefined CMap.

Returns:CMap

the font's UCS2 CMap if present

getDescendantFontback to summary
public PDCIDFont getDescendantFont()

Returns the descendant font.

Returns:PDCIDFont

the descendant font

getDisplacementback to summary
public Vector getDisplacement(int code) throws IOException

Overrides org.apache.pdfbox.pdmodel.font.PDFont.getDisplacement.

Doc from org.apache.pdfbox.pdmodel.font.PDFont.getDisplacement.

Returns the displacement vector (w0, w1) in text space, for the given character. For horizontal text only the x component is used, for vertical text only the y component.

Parameters
code:int

character code

Returns:Vector

displacement vector

Annotations
@Override
Exceptions
IOException:
if the data could not be read
getFontDescriptorback to summary
public PDFontDescriptor getFontDescriptor()

Overrides org.apache.pdfbox.pdmodel.font.PDFont.getFontDescriptor.

Implements org.apache.pdfbox.pdmodel.font.PDFontLike.getFontDescriptor.

Doc from org.apache.pdfbox.pdmodel.font.PDFontLike.getFontDescriptor.

Returns the font descriptor, may be null.

Returns:PDFontDescriptor

the font descriptor or null

Annotations
@Override
getFontMatrixback to summary
public Matrix getFontMatrix()

Overrides org.apache.pdfbox.pdmodel.font.PDFont.getFontMatrix.

Implements org.apache.pdfbox.pdmodel.font.PDFontLike.getFontMatrix.

Doc from org.apache.pdfbox.pdmodel.font.PDFontLike.getFontMatrix.

Returns the font matrix, which represents the transformation from glyph space to text space.

Returns:Matrix

the font matrix

Annotations
@Override
getGsubDataback to summary
public GsubData getGsubData()

Returns the GSubData if present.

Returns:GsubData

the GSubData if present

getHeightback to summary
public float getHeight(int code) throws IOException

Implements org.apache.pdfbox.pdmodel.font.PDFontLike.getHeight.

Doc from org.apache.pdfbox.pdmodel.font.PDFontLike.getHeight.

Returns the height of the given character, in glyph space. This can be expensive to calculate. Results are only approximate.

Warning

This method is deprecated in PDFBox 2.0 because there is no meaningful value which it can return. The getWidth(int) method returns the advance width of a glyph, but there is no corresponding advance height. The logical height of a character is the same for every character in a font, so if you want that, retrieve the font bbox's height. Otherwise if you want the visual bounds of the glyph then call getPath(..) on the appropriate PDFont subclass to retrieve the glyph outline as a GeneralPath. See the cyan rectangles in the DrawPrintTextLocations.java example to see this in action.

Parameters
code:int

character code

Returns:float

the height of the given character

Annotations
@Override
Exceptions
IOException:
if the height could not be read
getNameback to summary
public String getName()

Implements org.apache.pdfbox.pdmodel.font.PDFontLike.getName.

Doc from org.apache.pdfbox.pdmodel.font.PDFontLike.getName.

Returns the name of this font, either the PostScript "BaseName" or the Type 3 "Name".

Returns:String

the name of the font

Annotations
@Override
getNormalizedPathback to summary
public GeneralPath getNormalizedPath(int code) throws IOException

Implements org.apache.pdfbox.pdmodel.font.PDVectorFont.getNormalizedPath.

Doc from org.apache.pdfbox.pdmodel.font.PDVectorFont.getNormalizedPath.

Returns the normalized glyph path for the given character code in a PDF. The resulting path is normalized to the PostScript 1000 unit square, and fallback glyphs are returned where appropriate, e.g. for missing glyphs.

Parameters
code:int

character code in a PDF. Not to be confused with unicode.

Returns:GeneralPath

the normalized glyph path for the given character code

Annotations
@Override
Exceptions
IOException:
if the font could not be read
getPathback to summary
public GeneralPath getPath(int code) throws IOException

Implements org.apache.pdfbox.pdmodel.font.PDVectorFont.getPath.

Doc from org.apache.pdfbox.pdmodel.font.PDVectorFont.getPath.

Returns the glyph path for the given character code.

Parameters
code:int

character code in a PDF. Not to be confused with unicode.

Returns:GeneralPath

the glyph path for the given character code

Annotations
@Override
Exceptions
IOException:
if the font could not be read
getPositionVectorback to summary
public Vector getPositionVector(int code)

Overrides org.apache.pdfbox.pdmodel.font.PDFont.getPositionVector.

Implements org.apache.pdfbox.pdmodel.font.PDFontLike.getPositionVector.

Doc from org.apache.pdfbox.pdmodel.font.PDFontLike.getPositionVector.

Returns the position vector (v), in text space, for the given character. This represents the position of vertical origin relative to horizontal origin, for horizontal writing it will always be (0, 0). For vertical writing both x and y are set.

Parameters
code:int

character code

Returns:Vector

position vector

Annotations
@Override
getStandard14Widthback to summary
protected float getStandard14Width(int code)

Implements abstract org.apache.pdfbox.pdmodel.font.PDFont.getStandard14Width.

Doc from org.apache.pdfbox.pdmodel.font.PDFont.getStandard14Width.

Returns the glyph width from the AFM if this is a Standard 14 font.

Parameters
code:int

character code

Returns:float

width in 1/1000 text space

Annotations
@Override
getWidthback to summary
public float getWidth(int code) throws IOException

Overrides org.apache.pdfbox.pdmodel.font.PDFont.getWidth.

Implements org.apache.pdfbox.pdmodel.font.PDFontLike.getWidth.

Doc from org.apache.pdfbox.pdmodel.font.PDFontLike.getWidth.

Returns the advance width of the given character, in glyph space.

If you want the visual bounds of the glyph then call getPath(..) on the appropriate PDFont subclass to retrieve the glyph outline as a GeneralPath instead. See the cyan rectangles in the DrawPrintTextLocations.java example to see this in action.

Parameters
code:int

character code

Returns:float

the width of the given character

Annotations
@Override
Exceptions
IOException:
if the width could not be read
getWidthFromFontback to summary
public float getWidthFromFont(int code) throws IOException

Implements org.apache.pdfbox.pdmodel.font.PDFontLike.getWidthFromFont.

Doc from org.apache.pdfbox.pdmodel.font.PDFontLike.getWidthFromFont.

Returns the width of a glyph in the embedded font file.

Parameters
code:int

character code

Returns:float

width in glyph space

Annotations
@Override
Exceptions
IOException:
if the font could not be read
hasExplicitWidthback to summary
public boolean hasExplicitWidth(int code) throws IOException

Implements org.apache.pdfbox.pdmodel.font.PDFontLike.hasExplicitWidth.

Doc from org.apache.pdfbox.pdmodel.font.PDFontLike.hasExplicitWidth.

Returns true if the Font dictionary specifies an explicit width for the given glyph. This includes Width, W but not default widths entries.

Parameters
code:int

character code

Returns:boolean

true if the Font dictionary specifies an explicit width for the given glyph

Annotations
@Override
Exceptions
IOException:
if the font could not be read
hasGlyphback to summary
public boolean hasGlyph(int code) throws IOException

Implements org.apache.pdfbox.pdmodel.font.PDVectorFont.hasGlyph.

Doc from org.apache.pdfbox.pdmodel.font.PDVectorFont.hasGlyph.

Returns true if this font contains a glyph for the given character code in a PDF.

Parameters
code:int

character code in a PDF. Not to be confused with unicode.

Returns:boolean

true if this font contains a glyph for the given character code

Annotations
@Override
Exceptions
IOException:
if the font could not be read
isDamagedback to summary
public boolean isDamaged()

Implements org.apache.pdfbox.pdmodel.font.PDFontLike.isDamaged.

Doc from org.apache.pdfbox.pdmodel.font.PDFontLike.isDamaged.

Returns true if the embedded font file is damaged.

Returns:boolean

true if the embedded font file is damaged

Annotations
@Override
isEmbeddedback to summary
public boolean isEmbedded()

Implements org.apache.pdfbox.pdmodel.font.PDFontLike.isEmbedded.

Doc from org.apache.pdfbox.pdmodel.font.PDFontLike.isEmbedded.

Returns true if the font file is embedded in the PDF.

Returns:boolean

true if the font file is embedded in the PDF

Annotations
@Override
isStandard14back to summary
public boolean isStandard14()

Overrides org.apache.pdfbox.pdmodel.font.PDFont.isStandard14.

Doc from org.apache.pdfbox.pdmodel.font.PDFont.isStandard14.

Returns true if this font is one of the "Standard 14" fonts and receives special handling.

Returns:boolean

true if this font is one of the "Standard 14" fonts

Annotations
@Override
isVerticalback to summary
public boolean isVertical()

Implements abstract org.apache.pdfbox.pdmodel.font.PDFont.isVertical.

Doc from org.apache.pdfbox.pdmodel.font.PDFont.isVertical.

Returns true if the font uses vertical writing mode.

Returns:boolean

true if the font uses vertical writing mode

Annotations
@Override
loadback to summary
public static PDType0Font load(PDDocument doc, File file) throws IOException

Loads a TTF to be embedded and subset into a document as a Type 0 font. If you are loading a font for AcroForm, then use the 3-parameter constructor instead.

Parameters
doc:PDDocument

The PDF document that will hold the embedded font.

file:File

A TrueType font.

Returns:PDType0Font

A Type0 font with a CIDFontType2 descendant.

Exceptions
IOException:
If there is an error reading the font file.
loadback to summary
public static PDType0Font load(PDDocument doc, InputStream input) throws IOException

Loads a TTF to be embedded and subset into a document as a Type 0 font. If you are loading a font for AcroForm, then use the 3-parameter constructor instead.

Parameters
doc:PDDocument

The PDF document that will hold the embedded font.

input:InputStream

An input stream of a TrueType font. It will be closed before returning.

Returns:PDType0Font

A Type0 font with a CIDFontType2 descendant.

Exceptions
IOException:
If there is an error reading the font stream.
loadback to summary
public static PDType0Font load(PDDocument doc, InputStream input, boolean embedSubset) throws IOException

Loads a TTF to be embedded into a document as a Type 0 font.

Parameters
doc:PDDocument

The PDF document that will hold the embedded font.

input:InputStream

An input stream of a TrueType font. It will be closed before returning.

embedSubset:boolean

True if the font will be subset before embedding. Set this to false when creating a font for AcroForm.

Returns:PDType0Font

A Type0 font with a CIDFontType2 descendant.

Exceptions
IOException:
If there is an error reading the font stream.
loadback to summary
public static PDType0Font load(PDDocument doc, RandomAccessRead randomAccessRead, boolean embedSubset, boolean vertical) throws IOException

Loads a TTF to be embedded into a document as a Type 0 font.

Parameters
doc:PDDocument

The PDF document that will hold the embedded font.

randomAccessRead:RandomAccessRead

source of a TrueType font.

embedSubset:boolean

True if the font will be subset before embedding. Set this to false when creating a font for AcroForm.

vertical:boolean

whether to enable vertical substitutions.

Returns:PDType0Font

A Type0 font with a CIDFontType2 descendant.

Exceptions
IOException:
If there is an error reading the font stream.
loadback to summary
public static PDType0Font load(PDDocument doc, TrueTypeFont ttf, boolean embedSubset) throws IOException

Loads a TTF to be embedded into a document as a Type 0 font.

Parameters
doc:PDDocument

The PDF document that will hold the embedded font.

ttf:TrueTypeFont

A TrueType font.

embedSubset:boolean

True if the font will be subset before embedding. Set this to false when creating a font for AcroForm.

Returns:PDType0Font

A Type0 font with a CIDFontType2 descendant.

Exceptions
IOException:
If there is an error reading the font stream.
loadVerticalback to summary
public static PDType0Font loadVertical(PDDocument doc, File file) throws IOException

Loads a TTF to be embedded into a document as a vertical Type 0 font.

Parameters
doc:PDDocument

The PDF document that will hold the embedded font.

file:File

A TrueType font.

Returns:PDType0Font

A Type0 font with a CIDFontType2 descendant.

Exceptions
IOException:
If there is an error reading the font file.
loadVerticalback to summary
public static PDType0Font loadVertical(PDDocument doc, InputStream input) throws IOException

Loads a TTF to be embedded into a document as a vertical Type 0 font.

Parameters
doc:PDDocument

The PDF document that will hold the embedded font.

input:InputStream

A TrueType font.

Returns:PDType0Font

A Type0 font with a CIDFontType2 descendant.

Exceptions
IOException:
If there is an error reading the font stream.
loadVerticalback to summary
public static PDType0Font loadVertical(PDDocument doc, InputStream input, boolean embedSubset) throws IOException

Loads a TTF to be embedded into a document as a vertical Type 0 font.

Parameters
doc:PDDocument

The PDF document that will hold the embedded font.

input:InputStream

A TrueType font.

embedSubset:boolean

True if the font will be subset before embedding

Returns:PDType0Font

A Type0 font with a CIDFontType2 descendant.

Exceptions
IOException:
If there is an error reading the font stream.
loadVerticalback to summary
public static PDType0Font loadVertical(PDDocument doc, TrueTypeFont ttf, boolean embedSubset) throws IOException

Loads a TTF to be embedded into a document as a vertical Type 0 font.

Parameters
doc:PDDocument

The PDF document that will hold the embedded font.

ttf:TrueTypeFont

A TrueType font.

embedSubset:boolean

True if the font will be subset before embedding

Returns:PDType0Font

A Type0 font with a CIDFontType2 descendant.

Exceptions
IOException:
If there is an error reading the font stream.
readCodeback to summary
public int readCode(InputStream in) throws IOException

Implements abstract org.apache.pdfbox.pdmodel.font.PDFont.readCode.

Doc from org.apache.pdfbox.pdmodel.font.PDFont.readCode.

Reads a character code from a content stream string. Codes may be up to 4 bytes long.

Parameters
in:InputStream

string stream

Returns:int

character code

Annotations
@Override
Exceptions
IOException:
if the CMap or stream cannot be read
readEncodingback to summary
private void readEncoding() throws IOException

Reads the font's Encoding entry, which should be a CMap name/stream.

subsetback to summary
public void subset() throws IOException

Implements abstract org.apache.pdfbox.pdmodel.font.PDFont.subset.

Doc from org.apache.pdfbox.pdmodel.font.PDFont.subset.

Replaces this font with a subset containing only the given Unicode characters.

Annotations
@Override
Exceptions
IOException:
if the subset could not be written
toStringback to summary
public String toString()

Overrides org.apache.pdfbox.pdmodel.font.PDFont.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
toUnicodeback to summary
public String toUnicode(int code)

Overrides org.apache.pdfbox.pdmodel.font.PDFont.toUnicode.

Doc from org.apache.pdfbox.pdmodel.font.PDFont.toUnicode.

Returns the Unicode character sequence which corresponds to the given character code.

Parameters
code:int

character code

Returns:String

Unicode character(s)

Annotations
@Override
willBeSubsetback to summary
public boolean willBeSubset()

Implements abstract org.apache.pdfbox.pdmodel.font.PDFont.willBeSubset.

Doc from org.apache.pdfbox.pdmodel.font.PDFont.willBeSubset.

Returns true if this font will be subset when embedded.

Returns:boolean

true if this font will be subset when embedded

Annotations
@Override