public class Chunk extends java.lang.Object implements Element, MarkupAttributes
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);
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ACTION
Key for Action.
|
protected java.util.HashMap |
attributes
Contains some of the attributes for this Chunk.
|
static java.lang.String |
BACKGROUND
Key for background.
|
static java.lang.String |
COLOR
Key for color.
|
protected java.lang.StringBuffer |
content
This is the content of this chunk of text.
|
static java.lang.String |
ENCODING
Key for encoding.
|
protected Font |
font
This is the
Font of this chunk of text. |
static java.lang.String |
GENERICTAG
Key for generic tag.
|
static java.lang.String |
HSCALE
Key for text horizontal scaling.
|
static java.lang.String |
HYPHENATION
Key for hyphenation.
|
static java.lang.String |
IMAGE
Key for image.
|
static java.lang.String |
LOCALDESTINATION
Key for local destination.
|
static java.lang.String |
LOCALGOTO
Key for local goto.
|
protected java.util.Properties |
markupAttributes
Contains extra markupAttributes
|
static Chunk |
NEWLINE
This is a Chunk containing a newline.
|
static java.lang.String |
NEWPAGE
Key for newpage.
|
static Chunk |
NEXTPAGE
This is a Chunk containing a newpage.
|
static java.lang.String |
OBJECT_REPLACEMENT_CHARACTER
The character stand in for an image.
|
static java.lang.String |
PDFANNOTATION
Key for annotation.
|
static java.lang.String |
REMOTEGOTO
Key for remote goto.
|
static java.lang.String |
SKEW
Key for text skewing.
|
static java.lang.String |
SPLITCHARACTER
Key for split character.
|
static java.lang.String |
SUBSUPSCRIPT
Key for sub/superscript.
|
static java.lang.String |
TEXTRENDERMODE
Key for text rendering mode.
|
static java.lang.String |
UNDERLINE
Key for underline.
|
ALIGN_BASELINE, ALIGN_BOTTOM, ALIGN_CENTER, ALIGN_JUSTIFIED, ALIGN_JUSTIFIED_ALL, ALIGN_LEFT, ALIGN_MIDDLE, ALIGN_RIGHT, ALIGN_TOP, ALIGN_UNDEFINED, ANCHOR, ANNOTATION, AUTHOR, CCITT_BLACKIS1, CCITT_ENCODEDBYTEALIGN, CCITT_ENDOFBLOCK, CCITT_ENDOFLINE, CCITTG3_1D, CCITTG3_2D, CCITTG4, CELL, CHAPTER, CHUNK, CREATIONDATE, CREATOR, GRAPHIC, HEADER, IMGRAW, IMGTEMPLATE, JPEG, KEYWORDS, LIST, LISTITEM, MULTI_COLUMN_TEXT, PARAGRAPH, PHRASE, PRODUCER, PTABLE, RECTANGLE, ROW, SECTION, SUBJECT, TABLE, TITLE
Modifier | Constructor and Description |
---|---|
protected |
Chunk()
Empty constructor.
|
|
Chunk(char c)
Constructs a chunk of text with a char, without specifying a
Font
. |
|
Chunk(char c,
Font font)
Constructs a chunk of text with a char and a certain
Font . |
|
Chunk(Chunk ck)
A
Chunk copy constructor. |
|
Chunk(Image image,
float offsetX,
float offsetY)
Constructs a chunk containing an
Image . |
|
Chunk(Image image,
float offsetX,
float offsetY,
boolean changeLeading)
Constructs a chunk containing an
Image . |
|
Chunk(java.util.Properties attributes)
Returns a
Chunk that has been constructed taking in
account the value of some attributes . |
|
Chunk(java.lang.String content)
Constructs a chunk of text with a certain content, without specifying a
Font . |
|
Chunk(java.lang.String content,
Font font)
Constructs a chunk of text with a certain content and a certain
Font . |
Modifier and Type | Method and Description |
---|---|
static java.lang.Object[][] |
addToArray(java.lang.Object[][] original,
java.lang.Object[] item)
Utility method to extend an array.
|
java.lang.StringBuffer |
append(java.lang.String string)
appends some text to this
Chunk . |
java.lang.String |
content()
Returns the content of this
Chunk . |
Font |
font()
Gets the font of this
Chunk . |
java.util.HashMap |
getAttributes()
Gets the attributes for this
Chunk . |
java.util.ArrayList |
getChunks()
Gets all the chunks in this element.
|
float |
getHorizontalScaling()
Gets the horizontal scaling.
|
Image |
getImage()
Returns the image.
|
static java.util.Set |
getKeySet(java.util.Hashtable table)
Gets the keys of a Hashtable
|
java.lang.String |
getMarkupAttribute(java.lang.String name)
Returns the value of the specified attribute.
|
java.util.Set |
getMarkupAttributeNames()
Returns a
Set of String attribute names for the
MarkupAttributes implementor. |
java.util.Properties |
getMarkupAttributes()
Return a
Properties -object containing all the markupAttributes. |
float |
getTextRise()
Gets the text displacement relatiev to the baseline.
|
float |
getWidthPoint()
Gets the width of the Chunk in points.
|
boolean |
hasAttributes()
Checks the attributes of this
Chunk . |
boolean |
isEmpty()
Checks is this
Chunk is empty. |
static boolean |
isTag(java.lang.String tag)
Checks if a given tag corresponds with this object.
|
boolean |
process(ElementListener listener)
Processes the element by adding it (or the different parts) to an
ElementListener . |
Chunk |
setAction(PdfAction action)
Sets an action for this
Chunk . |
Chunk |
setAnchor(java.lang.String url)
Sets an anchor for this
Chunk . |
Chunk |
setAnchor(java.net.URL url)
Sets an anchor for this
Chunk . |
Chunk |
setAnnotation(PdfAnnotation annotation)
Sets a generic annotation to this
Chunk . |
private Chunk |
setAttribute(java.lang.String name,
java.lang.Object obj)
Sets an arbitrary attribute.
|
Chunk |
setBackground(java.awt.Color color)
Sets the color of the background
Chunk . |
Chunk |
setBackground(java.awt.Color color,
float extraLeft,
float extraBottom,
float extraRight,
float extraTop)
Sets the color and the size of the background
Chunk . |
void |
setFont(Font font)
Sets the font of this
Chunk . |
Chunk |
setGenericTag(java.lang.String text)
Sets the generic tag
Chunk . |
Chunk |
setHorizontalScaling(float scale)
Sets the text horizontal scaling.
|
Chunk |
setHyphenation(HyphenationEvent hyphenation)
sets the hyphenation engine to this
Chunk . |
Chunk |
setLocalDestination(java.lang.String name)
Sets a local destination for this
Chunk . |
Chunk |
setLocalGoto(java.lang.String name)
Sets a local goto for this
Chunk . |
void |
setMarkupAttribute(java.lang.String name,
java.lang.String value)
Sets the specified attribute.
|
void |
setMarkupAttributes(java.util.Properties markupAttributes)
Sets the markupAttributes.
|
Chunk |
setNewPage()
Sets a new page tag..
|
Chunk |
setRemoteGoto(java.lang.String filename,
int page)
Sets a goto for a remote destination for this
Chunk . |
Chunk |
setRemoteGoto(java.lang.String filename,
java.lang.String name)
Sets a goto for a remote destination for this
Chunk . |
Chunk |
setSkew(float alpha,
float beta)
Skews the text to simulate italic and other effects.
|
Chunk |
setSplitCharacter(SplitCharacter splitCharacter)
Sets the split characters.
|
Chunk |
setTextRenderMode(int mode,
float strokeWidth,
java.awt.Color strokeColor)
Sets the text rendering mode.
|
Chunk |
setTextRise(float rise)
Sets the text displacement relative to the baseline.
|
Chunk |
setUnderline(java.awt.Color color,
float thickness,
float thicknessMul,
float yPosition,
float yPositionMul,
int cap)
Sets an horizontal line that can be an underline or a strikethrough.
|
Chunk |
setUnderline(float thickness,
float yPosition)
Sets an horizontal line that can be an underline or a strikethrough.
|
java.lang.String |
toString()
Returns the content of this
Chunk . |
int |
type()
Gets the type of the text element.
|
public static final java.lang.String OBJECT_REPLACEMENT_CHARACTER
public static final Chunk NEWLINE
public static final Chunk NEXTPAGE
public static final java.lang.String SUBSUPSCRIPT
public static final java.lang.String UNDERLINE
public static final java.lang.String COLOR
public static final java.lang.String ENCODING
public static final java.lang.String REMOTEGOTO
public static final java.lang.String LOCALGOTO
public static final java.lang.String LOCALDESTINATION
public static final java.lang.String IMAGE
public static final java.lang.String GENERICTAG
public static final java.lang.String NEWPAGE
public static final java.lang.String SPLITCHARACTER
public static final java.lang.String ACTION
public static final java.lang.String BACKGROUND
public static final java.lang.String PDFANNOTATION
public static final java.lang.String HYPHENATION
public static final java.lang.String TEXTRENDERMODE
public static final java.lang.String SKEW
public static final java.lang.String HSCALE
protected java.lang.StringBuffer content
protected Font font
Font
of this chunk of text.protected java.util.HashMap attributes
protected java.util.Properties markupAttributes
protected Chunk()
public Chunk(Chunk ck)
Chunk
copy constructor.ck
- the Chunk
to be copiedpublic Chunk(java.lang.String content, Font font)
Font
.content
- the contentfont
- the fontpublic Chunk(java.lang.String content)
Font
.content
- the contentpublic Chunk(char c, Font font)
Font
.c
- the contentfont
- the fontpublic Chunk(char c)
Font
.c
- the contentpublic Chunk(Image image, float offsetX, float offsetY)
Image
.image
- the imageoffsetX
- the image offset in the x directionoffsetY
- the image offset in the y directionpublic Chunk(Image image, float offsetX, float offsetY, boolean changeLeading)
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 imagepublic Chunk(java.util.Properties attributes)
Chunk
that has been constructed taking in
account the value of some attributes .attributes
- Some attributespublic boolean process(ElementListener listener)
ElementListener
.public int type()
public java.util.ArrayList getChunks()
public java.lang.StringBuffer append(java.lang.String string)
Chunk
.string
- String
StringBuffer
public Font font()
Chunk
.Font
public void setFont(Font font)
Chunk
.font
- a Font
public java.lang.String content()
Chunk
.String
public java.lang.String toString()
Chunk
.public boolean isEmpty()
Chunk
is empty.false
if the Chunk contains other characters than
space.public float getWidthPoint()
public Chunk setTextRise(float rise)
It can be used to implement sub/superscript.
rise
- the displacement in pointsChunk
public float getTextRise()
public Chunk setTextRenderMode(int mode, float strokeWidth, java.awt.Color strokeColor)
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
colorChunk
public Chunk setSkew(float alpha, float beta)
alpha=0
and beta=12
.alpha
- the first angle in degreesbeta
- the second angle in degreesChunk
public Chunk setHorizontalScaling(float scale)
scale
- the horizontal scaling factorChunk
public float getHorizontalScaling()
public Chunk setAction(PdfAction action)
Chunk
.action
- the actionChunk
public Chunk setAnchor(java.net.URL url)
Chunk
.url
- the URL
to link toChunk
public Chunk setAnchor(java.lang.String url)
Chunk
.url
- the url to link toChunk
public Chunk setLocalGoto(java.lang.String name)
Chunk
.
There must be a local destination matching the name.
name
- the name of the destination to go toChunk
public Chunk setBackground(java.awt.Color color)
Chunk
.color
- the color of the backgroundChunk
public Chunk setBackground(java.awt.Color color, float extraLeft, float extraBottom, float extraRight, float extraTop)
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 topChunk
public Chunk setUnderline(float thickness, float yPosition)
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 baselineChunk
public Chunk setUnderline(java.awt.Color color, float thickness, float thicknessMul, float yPosition, float yPositionMul, int cap)
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_SQUAREChunk
public static java.lang.Object[][] addToArray(java.lang.Object[][] original, java.lang.Object[] item)
original
- the original array or null
item
- the item to be added to the arraypublic Chunk setAnnotation(PdfAnnotation annotation)
Chunk
.annotation
- the annotationChunk
public Chunk setHyphenation(HyphenationEvent hyphenation)
Chunk
.hyphenation
- the hyphenation engineChunk
public Chunk setRemoteGoto(java.lang.String filename, java.lang.String name)
Chunk
.filename
- the file name of the destination documentname
- the name of the destination to go toChunk
public Chunk setRemoteGoto(java.lang.String filename, int page)
Chunk
.filename
- the file name of the destination documentpage
- the page of the destination to go to. First page is 1Chunk
public Chunk setLocalDestination(java.lang.String name)
Chunk
.name
- the name for this destinationChunk
public Chunk setGenericTag(java.lang.String text)
Chunk
.
The text for this tag can be retrieved with PdfPageEvent
.
text
- the text for the tagChunk
public Chunk setSplitCharacter(SplitCharacter splitCharacter)
splitCharacter
- the SplitCharacter
interfaceChunk
public Chunk setNewPage()
Chunk
private Chunk setAttribute(java.lang.String name, java.lang.Object obj)
name
- the key for the attributeobj
- the value of the attributeChunk
public java.util.HashMap getAttributes()
Chunk
.
It may be null.
Chunk
public boolean hasAttributes()
Chunk
.public Image getImage()
public static boolean isTag(java.lang.String tag)
tag
- the given tagpublic void setMarkupAttribute(java.lang.String name, java.lang.String value)
MarkupAttributes
setMarkupAttribute
in interface MarkupAttributes
name
- String
attribute name.value
- String
attribute value.MarkupAttributes.setMarkupAttribute(java.lang.String,
java.lang.String)
public void setMarkupAttributes(java.util.Properties markupAttributes)
MarkupAttributes
setMarkupAttributes
in interface MarkupAttributes
markupAttributes
- a Properties
-object containing markupattributesMarkupAttributes.setMarkupAttributes(java.util.Properties)
public java.lang.String getMarkupAttribute(java.lang.String name)
MarkupAttributes
getMarkupAttribute
in interface MarkupAttributes
name
- String
attribute name.String
.MarkupAttributes.getMarkupAttribute(java.lang.String)
public java.util.Set getMarkupAttributeNames()
MarkupAttributes
Set
of String
attribute names for the
MarkupAttributes
implementor.getMarkupAttributeNames
in interface MarkupAttributes
Set
.MarkupAttributes.getMarkupAttributeNames()
public java.util.Properties getMarkupAttributes()
MarkupAttributes
Properties
-object containing all the markupAttributes.getMarkupAttributes
in interface MarkupAttributes
Properties
MarkupAttributes.getMarkupAttributes()
public static java.util.Set getKeySet(java.util.Hashtable table)
table
- a Hashtable