This is the smallest significant part of text that can be added to a
document.
Most elements can be divided in one or more
Chunk
s. A chunk
is a
String
with a certain
Font
. All other
layout parameters should be defined in the object to which this chunk of text
is added.
Example:
Chunk chunk = new Chunk("Hello world",
FontFactory.getFont(FontFactory.COURIER, 20, Font.ITALIC, new Color(255, 0,
0))); document.add(chunk);
ACTION
public static final String ACTION
Key for Action.
BACKGROUND
public static final String BACKGROUND
Key for background.
COLOR
public static final String COLOR
Key for color.
ENCODING
public static final String ENCODING
Key for encoding.
GENERICTAG
public static final String GENERICTAG
Key for generic tag.
HSCALE
public static final String HSCALE
Key for text horizontal scaling.
HYPHENATION
public static final String HYPHENATION
Key for hyphenation.
IMAGE
public static final String IMAGE
Key for image.
LOCALDESTINATION
public static final String LOCALDESTINATION
Key for local destination.
LOCALGOTO
public static final String LOCALGOTO
Key for local goto.
NEWLINE
public static final Chunk NEWLINE
This is a Chunk containing a newline.
NEWPAGE
public static final String NEWPAGE
Key for newpage.
NEXTPAGE
public static final Chunk NEXTPAGE
This is a Chunk containing a newpage.
OBJECT_REPLACEMENT_CHARACTER
public static final String OBJECT_REPLACEMENT_CHARACTER
The character stand in for an image.
PDFANNOTATION
public static final String PDFANNOTATION
Key for annotation.
REMOTEGOTO
public static final String REMOTEGOTO
Key for remote goto.
SKEW
public static final String SKEW
Key for text skewing.
SPLITCHARACTER
public static final String SPLITCHARACTER
Key for split character.
SUBSUPSCRIPT
public static final String SUBSUPSCRIPT
Key for sub/superscript.
TEXTRENDERMODE
public static final String TEXTRENDERMODE
Key for text rendering mode.
UNDERLINE
public static final String UNDERLINE
Key for underline.
attributes
protected HashMap attributes
Contains some of the attributes for this Chunk.
content
protected StringBuffer content
This is the content of this chunk of text.
font
protected Font font
This is the Font
of this chunk of text.
markupAttributes
protected Properties markupAttributes
Contains extra markupAttributes
Chunk
protected Chunk()
Empty constructor.
Chunk
public Chunk(Properties attributes)
Returns a Chunk
that has been constructed taking in
account the value of some attributes .
attributes
- Some attributes
Chunk
public Chunk(String content)
Constructs a chunk of text with a certain content, without specifying a
Font
.
Chunk
public Chunk(String content,
Font font)
Constructs a chunk of text with a certain content and a certain
Font
.
content
- the contentfont
- the font
Chunk
public Chunk(char c)
Constructs a chunk of text with a char, without specifying a Font
.
Chunk
public Chunk(char c,
Font font)
Constructs a chunk of text with a char and a certain Font
.
c
- the contentfont
- the font
Chunk
public Chunk(Chunk ck)
A Chunk
copy constructor.
ck
- the Chunk
to be copied
Chunk
public Chunk(Image image,
float offsetX,
float offsetY)
Constructs a chunk containing an Image
.
image
- the imageoffsetX
- the image offset in the x directionoffsetY
- the image offset in the y direction
Chunk
public Chunk(Image image,
float offsetX,
float offsetY,
boolean changeLeading)
Constructs a chunk containing an Image
.
image
- the imageoffsetX
- the image offset in the x directionoffsetY
- the image offset in the y directionchangeLeading
- true if the leading has to be adapted to the image
addToArray
public static Object[][] addToArray(original[][] ,
item[] )
Utility method to extend an array.
- a new array with the item appended
append
public StringBuffer append(String string)
appends some text to this Chunk
.
content
public String content()
Returns the content of this Chunk
.
font
public Font font()
Gets the font of this Chunk
.
getAttributes
public HashMap getAttributes()
Gets the attributes for this
Chunk
.
It may be null.
- the attributes for this
Chunk
getChunks
public ArrayList getChunks()
Gets all the chunks in this element.
- getChunks in interface Element
getHorizontalScaling
public float getHorizontalScaling()
Gets the horizontal scaling.
getImage
public Image getImage()
Returns the image.
getKeySet
public static Set getKeySet(Hashtable table)
Gets the keys of a Hashtable
- the keyset of a Hashtable (or an empty set if table is null)
getTextRise
public float getTextRise()
Gets the text displacement relatiev to the baseline.
getWidthPoint
public float getWidthPoint()
Gets the width of the Chunk in points.
hasAttributes
public boolean hasAttributes()
Checks the attributes of this Chunk
.
- false if there aren't any.
isEmpty
public boolean isEmpty()
Checks is this Chunk
is empty.
false
if the Chunk contains other characters than
space.
isTag
public static boolean isTag(String tag)
Checks if a given tag corresponds with this object.
- true if the tag corresponds
process
public boolean process(ElementListener listener)
Processes the element by adding it (or the different parts) to an
ElementListener
.
- process in interface Element
listener
- an ElementListener
true
if the element was processed successfully
setAction
public Chunk setAction(PdfAction action)
Sets an action for this Chunk
.
setAnchor
public Chunk setAnchor(String url)
Sets an anchor for this Chunk
.
setAnchor
public Chunk setAnchor(URL url)
Sets an anchor for this Chunk
.
setAnnotation
public Chunk setAnnotation(PdfAnnotation annotation)
Sets a generic annotation to this Chunk
.
annotation
- the annotation
setAttribute
private Chunk setAttribute(String name,
Object obj)
Sets an arbitrary attribute.
name
- the key for the attributeobj
- the value of the attribute
setBackground
public Chunk setBackground(Color color)
Sets the color of the background Chunk
.
color
- the color of the background
setBackground
public Chunk setBackground(Color color,
float extraLeft,
float extraBottom,
float extraRight,
float extraTop)
Sets the color and the size of the background Chunk
.
color
- the color of the backgroundextraLeft
- increase the size of the rectangle in the leftextraBottom
- increase the size of the rectangle in the bottomextraRight
- increase the size of the rectangle in the rightextraTop
- increase the size of the rectangle in the top
setFont
public void setFont(Font font)
Sets the font of this Chunk
.
setGenericTag
public Chunk setGenericTag(String text)
Sets the generic tag
Chunk
.
The text for this tag can be retrieved with
PdfPageEvent
.
text
- the text for the tag
setHorizontalScaling
public Chunk setHorizontalScaling(float scale)
Sets the text horizontal scaling. A value of 1 is normal and a value of
0.5f shrinks the text to half it's width.
scale
- the horizontal scaling factor
setHyphenation
public Chunk setHyphenation(HyphenationEvent hyphenation)
sets the hyphenation engine to this Chunk
.
hyphenation
- the hyphenation engine
setLocalDestination
public Chunk setLocalDestination(String name)
Sets a local destination for this Chunk
.
name
- the name for this destination
setLocalGoto
public Chunk setLocalGoto(String name)
Sets a local goto for this
Chunk
.
There must be a local destination matching the name.
name
- the name of the destination to go to
setNewPage
public Chunk setNewPage()
Sets a new page tag..
setRemoteGoto
public Chunk setRemoteGoto(String filename,
String name)
Sets a goto for a remote destination for this Chunk
.
filename
- the file name of the destination documentname
- the name of the destination to go to
setRemoteGoto
public Chunk setRemoteGoto(String filename,
int page)
Sets a goto for a remote destination for this Chunk
.
filename
- the file name of the destination documentpage
- the page of the destination to go to. First page is 1
setSkew
public Chunk setSkew(float alpha,
float beta)
Skews the text to simulate italic and other effects. Try alpha=0
and beta=12
.
alpha
- the first angle in degreesbeta
- the second angle in degrees
setSplitCharacter
public Chunk setSplitCharacter(SplitCharacter splitCharacter)
Sets the split characters.
splitCharacter
- the SplitCharacter
interface
setTextRenderMode
public Chunk setTextRenderMode(int mode,
float strokeWidth,
Color strokeColor)
Sets the text rendering mode. It can outline text, simulate bold and make
text invisible.
mode
- the text rendering mode. It can be
PdfContentByte.TEXT_RENDER_MODE_FILL
,
PdfContentByte.TEXT_RENDER_MODE_STROKE
,
PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE
and
PdfContentByte.TEXT_RENDER_MODE_INVISIBLE
.strokeWidth
- the stroke line width for the modes
PdfContentByte.TEXT_RENDER_MODE_STROKE
and
PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE
.strokeColor
- the stroke color or null
to follow the text
color
setTextRise
public Chunk setTextRise(float rise)
Sets the text displacement relative to the baseline. Positive values rise
the text, negative values lower the text.
It can be used to implement sub/superscript.
rise
- the displacement in points
setUnderline
public Chunk setUnderline(Color color,
float thickness,
float thicknessMul,
float yPosition,
float yPositionMul,
int cap)
Sets an horizontal line that can be an underline or a strikethrough.
Actually, the line can be anywhere vertically and has always the
Chunk
width. Multiple call to this method will produce multiple
lines.
color
- the color of the line or null
to follow the
text colorthickness
- the absolute thickness of the linethicknessMul
- the thickness multiplication factor with the font sizeyPosition
- the absolute y position relative to the baselineyPositionMul
- the position multiplication factor with the font sizecap
- the end line cap. Allowed values are
PdfContentByte.LINE_CAP_BUTT, PdfContentByte.LINE_CAP_ROUND
and PdfContentByte.LINE_CAP_PROJECTING_SQUARE
setUnderline
public Chunk setUnderline(float thickness,
float yPosition)
Sets an horizontal line that can be an underline or a strikethrough.
Actually, the line can be anywhere vertically and has always the
Chunk
width. Multiple call to this method will produce multiple
lines.
thickness
- the absolute thickness of the lineyPosition
- the absolute y position relative to the baseline
toString
public String toString()
Returns the content of this Chunk
.
- toString in interface Element
type
public int type()
Gets the type of the text element.
- type in interface Element