com.lowagie.text

Class Chunk

public class Chunk extends Object implements Element

This is the smallest significant part of text that can be added to a document.

Most elements can be divided in one or more Chunks. 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);
 
 
Field Summary
static StringACTION
Key for Action.
protected HashMapattributes
Contains some of the attributes for this Chunk.
static StringBACKGROUND
Key for background.
protected StringBuffercontent
This is the content of this chunk of text.
static StringCOLOR
Key for color.
static StringENCODING
Key for encoding.
protected Fontfont
This is the Font of this chunk of text.
static StringGENERICTAG
Key for generic tag.
static StringHSCALE
Key for text horizontal scaling.
static StringHYPHENATION
Key for hyphenation.
static StringIMAGE
Key for image.
static StringLOCALDESTINATION
Key for local destination.
static StringLOCALGOTO
Key for local goto.
static ChunkNEWLINE
This is a Chunk containing a newline.
static StringNEWPAGE
Key for newpage.
static ChunkNEXTPAGE
This is a Chunk containing a newpage.
static StringOBJECT_REPLACEMENT_CHARACTER
The character stand in for an image.
static StringPDFANNOTATION
Key for annotation.
static StringREMOTEGOTO
Key for remote goto.
static StringSKEW
Key for text skewing.
static StringSPLITCHARACTER
Key for split character.
static StringSUBSUPSCRIPT
Key for sub/superscript.
static StringTEXTRENDERMODE
Key for text rendering mode.
static StringUNDERLINE
Key for underline.
Constructor Summary
Chunk()
Empty constructor.
Chunk(Chunk ck)
A Chunk copy constructor.
Chunk(String content, Font font)
Constructs a chunk of text with a certain content and a certain Font.
Chunk(String content)
Constructs a chunk of text with a certain content, without specifying a Font.
Chunk(char c, Font font)
Constructs a chunk of text with a char and a certain Font.
Chunk(char c)
Constructs a chunk of text with a char, without specifying a Font .
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(Properties attributes)
Returns a Chunk that has been constructed taking in account the value of some attributes .
Method Summary
static Object[][]addToArray(Object[][] original, Object[] item)
Utility method to extend an array.
StringBufferappend(String string)
appends some text to this Chunk.
Stringcontent()
Returns the content of this Chunk.
Fontfont()
Gets the font of this Chunk.
HashMapgetAttributes()
Gets the attributes for this Chunk.
ArrayListgetChunks()
Gets all the chunks in this element.
StringgetContent()
Returns the content of this Chunk.
FontgetFont()
Gets the font of this Chunk.
floatgetHorizontalScaling()
Gets the horizontal scaling.
ImagegetImage()
Returns the image.
static SetgetKeySet(Hashtable table)
Gets the keys of a Hashtable
floatgetTextRise()
Gets the text displacement relatiev to the baseline.
floatgetWidthPoint()
Gets the width of the Chunk in points.
booleanhasAttributes()
Checks the attributes of this Chunk.
booleanisEmpty()
Checks is this Chunk is empty.
booleanprocess(ElementListener listener)
Processes the element by adding it (or the different parts) to an ElementListener.
ChunksetAction(PdfAction action)
Sets an action for this Chunk.
ChunksetAnchor(URL url)
Sets an anchor for this Chunk.
ChunksetAnchor(String url)
Sets an anchor for this Chunk.
ChunksetAnnotation(PdfAnnotation annotation)
Sets a generic annotation to this Chunk.
ChunksetAttribute(String name, Object obj)
Sets an arbitrary attribute.
ChunksetBackground(Color color)
Sets the color of the background Chunk.
ChunksetBackground(Color color, float extraLeft, float extraBottom, float extraRight, float extraTop)
Sets the color and the size of the background Chunk.
voidsetFont(Font font)
Sets the font of this Chunk.
ChunksetGenericTag(String text)
Sets the generic tag Chunk.
ChunksetHorizontalScaling(float scale)
Sets the text horizontal scaling.
ChunksetHyphenation(HyphenationEvent hyphenation)
sets the hyphenation engine to this Chunk.
ChunksetLocalDestination(String name)
Sets a local destination for this Chunk.
ChunksetLocalGoto(String name)
Sets a local goto for this Chunk.
ChunksetNewPage()
Sets a new page tag..
ChunksetRemoteGoto(String filename, String name)
Sets a goto for a remote destination for this Chunk.
ChunksetRemoteGoto(String filename, int page)
Sets a goto for a remote destination for this Chunk.
ChunksetSkew(float alpha, float beta)
Skews the text to simulate italic and other effects.
ChunksetSplitCharacter(SplitCharacter splitCharacter)
Sets the split characters.
ChunksetTextRenderMode(int mode, float strokeWidth, Color strokeColor)
Sets the text rendering mode.
ChunksetTextRise(float rise)
Sets the text displacement relative to the baseline.
ChunksetUnderline(float thickness, float yPosition)
Sets an horizontal line that can be an underline or a strikethrough.
ChunksetUnderline(Color color, float thickness, float thicknessMul, float yPosition, float yPositionMul, int cap)
Sets an horizontal line that can be an underline or a strikethrough.
StringtoString()
Returns the content of this Chunk.
inttype()
Gets the type of the text element.

Field Detail

ACTION

public static final String ACTION
Key for Action.

attributes

protected HashMap attributes
Contains some of the attributes for this Chunk.

BACKGROUND

public static final String BACKGROUND
Key for background.

content

protected StringBuffer content
This is the content of this chunk of text.

COLOR

public static final String COLOR
Key for color.

ENCODING

public static final String ENCODING
Key for encoding.

font

protected Font font
This is the Font of this chunk of text.

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.

Constructor Detail

Chunk

public Chunk()
Empty constructor.

Chunk

public Chunk(Chunk ck)
A Chunk copy constructor.

Parameters: ck the Chunk to be copied

Chunk

public Chunk(String content, Font font)
Constructs a chunk of text with a certain content and a certain Font.

Parameters: content the content font the font

Chunk

public Chunk(String content)
Constructs a chunk of text with a certain content, without specifying a Font.

Parameters: content the content

Chunk

public Chunk(char c, Font font)
Constructs a chunk of text with a char and a certain Font.

Parameters: c the content font the font

Chunk

public Chunk(char c)
Constructs a chunk of text with a char, without specifying a Font .

Parameters: c the content

Chunk

public Chunk(Image image, float offsetX, float offsetY)
Constructs a chunk containing an Image.

Parameters: image the image offsetX the image offset in the x direction offsetY the image offset in the y direction

Chunk

public Chunk(Image image, float offsetX, float offsetY, boolean changeLeading)
Constructs a chunk containing an Image.

Parameters: image the image offsetX the image offset in the x direction offsetY the image offset in the y direction changeLeading true if the leading has to be adapted to the image

Chunk

public Chunk(Properties attributes)

Deprecated: use ElementFactory.getChunk()

Returns a Chunk that has been constructed taking in account the value of some attributes .

Parameters: attributes Some attributes

Method Detail

addToArray

public static Object[][] addToArray(Object[][] original, Object[] item)

Deprecated: Use (Object[][],Object[]) instead

Utility method to extend an array.

Parameters: original the original array or null item the item to be added to the array

Returns: a new array with the item appended

append

public StringBuffer append(String string)
appends some text to this Chunk.

Parameters: string String

Returns: a StringBuffer

content

public String content()

Deprecated: Use getContent instead

Returns the content of this Chunk.

Returns: a String

font

public Font font()

Deprecated: Use getFont instead

Gets the font of this Chunk.

Returns: a Font

getAttributes

public HashMap getAttributes()
Gets the attributes for this Chunk.

It may be null.

Returns: the attributes for this Chunk

getChunks

public ArrayList getChunks()
Gets all the chunks in this element.

Returns: an ArrayList

getContent

public String getContent()
Returns the content of this Chunk.

Returns: a String

getFont

public Font getFont()
Gets the font of this Chunk.

Returns: a Font

getHorizontalScaling

public float getHorizontalScaling()
Gets the horizontal scaling.

Returns: a percentage in float

getImage

public Image getImage()
Returns the image.

Returns: the image

getKeySet

public static Set getKeySet(Hashtable table)

Deprecated: Use getKeySet instead

Gets the keys of a Hashtable

Parameters: table a Hashtable

Returns: 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.

Returns: a displacement in points

getWidthPoint

public float getWidthPoint()
Gets the width of the Chunk in points.

Returns: a width in points

hasAttributes

public boolean hasAttributes()
Checks the attributes of this Chunk.

Returns: false if there aren't any.

isEmpty

public boolean isEmpty()
Checks is this Chunk is empty.

Returns: false if the Chunk contains other characters than space.

process

public boolean process(ElementListener listener)
Processes the element by adding it (or the different parts) to an ElementListener.

Parameters: listener an ElementListener

Returns: true if the element was processed successfully

setAction

public Chunk setAction(PdfAction action)
Sets an action for this Chunk.

Parameters: action the action

Returns: this Chunk

setAnchor

public Chunk setAnchor(URL url)
Sets an anchor for this Chunk.

Parameters: url the URL to link to

Returns: this Chunk

setAnchor

public Chunk setAnchor(String url)
Sets an anchor for this Chunk.

Parameters: url the url to link to

Returns: this Chunk

setAnnotation

public Chunk setAnnotation(PdfAnnotation annotation)
Sets a generic annotation to this Chunk.

Parameters: annotation the annotation

Returns: this Chunk

setAttribute

private Chunk setAttribute(String name, Object obj)
Sets an arbitrary attribute.

Parameters: name the key for the attribute obj the value of the attribute

Returns: this Chunk

setBackground

public Chunk setBackground(Color color)
Sets the color of the background Chunk.

Parameters: color the color of the background

Returns: this Chunk

setBackground

public Chunk setBackground(Color color, float extraLeft, float extraBottom, float extraRight, float extraTop)
Sets the color and the size of the background Chunk.

Parameters: color the color of the background extraLeft increase the size of the rectangle in the left extraBottom increase the size of the rectangle in the bottom extraRight increase the size of the rectangle in the right extraTop increase the size of the rectangle in the top

Returns: this Chunk

setFont

public void setFont(Font font)
Sets the font of this Chunk.

Parameters: font a Font

setGenericTag

public Chunk setGenericTag(String text)
Sets the generic tag Chunk.

The text for this tag can be retrieved with PdfPageEvent.

Parameters: text the text for the tag

Returns: this Chunk

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.

Parameters: scale the horizontal scaling factor

Returns: this Chunk

setHyphenation

public Chunk setHyphenation(HyphenationEvent hyphenation)
sets the hyphenation engine to this Chunk.

Parameters: hyphenation the hyphenation engine

Returns: this Chunk

setLocalDestination

public Chunk setLocalDestination(String name)
Sets a local destination for this Chunk.

Parameters: name the name for this destination

Returns: this Chunk

setLocalGoto

public Chunk setLocalGoto(String name)
Sets a local goto for this Chunk.

There must be a local destination matching the name.

Parameters: name the name of the destination to go to

Returns: this Chunk

setNewPage

public Chunk setNewPage()
Sets a new page tag..

Returns: this Chunk

setRemoteGoto

public Chunk setRemoteGoto(String filename, String name)
Sets a goto for a remote destination for this Chunk.

Parameters: filename the file name of the destination document name the name of the destination to go to

Returns: this Chunk

setRemoteGoto

public Chunk setRemoteGoto(String filename, int page)
Sets a goto for a remote destination for this Chunk.

Parameters: filename the file name of the destination document page the page of the destination to go to. First page is 1

Returns: this Chunk

setSkew

public Chunk setSkew(float alpha, float beta)
Skews the text to simulate italic and other effects. Try alpha=0 and beta=12.

Parameters: alpha the first angle in degrees beta the second angle in degrees

Returns: this Chunk

setSplitCharacter

public Chunk setSplitCharacter(SplitCharacter splitCharacter)
Sets the split characters.

Parameters: splitCharacter the SplitCharacter interface

Returns: this Chunk

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.

Parameters: 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

Returns: this Chunk

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.

Parameters: rise the displacement in points

Returns: this Chunk

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.

Parameters: thickness the absolute thickness of the line yPosition the absolute y position relative to the baseline

Returns: this Chunk

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.

Parameters: color the color of the line or null to follow the text color thickness the absolute thickness of the line thicknessMul the thickness multiplication factor with the font size yPosition the absolute y position relative to the baseline yPositionMul the position multiplication factor with the font size cap the end line cap. Allowed values are PdfContentByte.LINE_CAP_BUTT, PdfContentByte.LINE_CAP_ROUND and PdfContentByte.LINE_CAP_PROJECTING_SQUARE

Returns: this Chunk

toString

public String toString()
Returns the content of this Chunk.

Returns: a String

type

public int type()
Gets the type of the text element.

Returns: a type