public class Chunk extends Object implements Element, IAccessibleElement
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 BaseColor(255, 0, 0))); document.add(chunk);
Modifier and Type | Field and Description |
---|---|
protected HashMap<PdfName,PdfObject> |
accessibleAttributes |
static String |
ACTION
Key for Action.
|
protected HashMap<String,Object> |
attributes
Contains some of the attributes for this Chunk.
|
static String |
BACKGROUND
Key for background.
|
static String |
CHAR_SPACING
Key for character spacing.
|
static String |
COLOR
Key for color.
|
protected StringBuffer |
content
This is the content of this chunk of text.
|
static String |
ENCODING
Key for encoding.
|
protected Font |
font
This is the Font of this chunk of text.
|
static String |
GENERICTAG
Key for generic tag.
|
static String |
HSCALE
Key for text horizontal scaling.
|
static String |
HYPHENATION
Key for hyphenation.
|
static String |
IMAGE
Key for image.
|
static String |
LINEHEIGHT
Key for line-height (alternative for leading in Phrase).
|
static String |
LOCALDESTINATION
Key for local destination.
|
static String |
LOCALGOTO
Key for local goto.
|
static Chunk |
NEWLINE
This is a Chunk containing a newline.
|
static String |
NEWPAGE
Key for newpage.
|
static Chunk |
NEXTPAGE
This is a Chunk containing a newpage.
|
static String |
OBJECT_REPLACEMENT_CHARACTER
The character stand in for an image or a separator.
|
static String |
PDFANNOTATION
Key for annotation.
|
static String |
REMOTEGOTO
Key for remote goto.
|
protected PdfName |
role |
static String |
SEPARATOR
Key for drawInterface of the Separator.
|
static String |
SKEW
Key for text skewing.
|
static Chunk |
SPACETABBING |
static String |
SPLITCHARACTER
Key for split character.
|
static String |
SUBSUPSCRIPT
Key for sub/superscript.
|
static String |
TAB
Key for drawInterface of the tab.
|
static Chunk |
TABBING |
static String |
TABSETTINGS
Key for tab stops of the tab.
|
static String |
TEXTRENDERMODE
Key for text rendering mode.
|
static String |
UNDERLINE
Key for underline.
|
static String |
WHITESPACE |
static String |
WORD_SPACING
Key for word spacing.
|
ALIGN_BASELINE, ALIGN_BOTTOM, ALIGN_CENTER, ALIGN_JUSTIFIED, ALIGN_JUSTIFIED_ALL, ALIGN_LEFT, ALIGN_MIDDLE, ALIGN_RIGHT, ALIGN_TOP, ALIGN_UNDEFINED, ANCHOR, ANNOTATION, AUTHOR, BODY, CCITT_BLACKIS1, CCITT_ENCODEDBYTEALIGN, CCITT_ENDOFBLOCK, CCITT_ENDOFLINE, CCITTG3_1D, CCITTG3_2D, CCITTG4, CHAPTER, CHUNK, CREATIONDATE, CREATOR, DIV, HEADER, IMGRAW, IMGTEMPLATE, JBIG2, JPEG, JPEG2000, KEYWORDS, LANGUAGE, LIST, LISTITEM, MARKED, PARAGRAPH, PHRASE, PRODUCER, PTABLE, RECTANGLE, SECTION, SUBJECT, TITLE, WRITABLE_DIRECT, YMARK
Constructor and Description |
---|
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(DrawInterface separator)
Creates a separator Chunk.
|
Chunk(DrawInterface separator, boolean vertical)
Creates a separator Chunk.
|
Chunk(DrawInterface separator, float tabPosition)
Deprecated.
|
Chunk(DrawInterface separator, float tabPosition, boolean newline)
Deprecated.
|
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(String content)
Constructs a chunk of text with a certain content, without specifying a Font .
|
Chunk(String content, Font font)
Constructs a chunk of text with a certain content and a certain Font .
|
Modifier and Type | Method and Description |
---|---|
StringBuffer |
append(String string)
appends some text to this Chunk .
|
static Chunk |
createTabspace()
Deprecated.
|
static Chunk |
createTabspace(float spacing)
Deprecated.
|
static Chunk |
createWhitespace(String content) |
static Chunk |
createWhitespace(String content, boolean preserve) |
PdfObject |
getAccessibleAttribute(PdfName key)
Get the attribute of accessible element (everything in A dictionary + Lang , Alt , ActualText , E ).
|
HashMap<PdfName,PdfObject> |
getAccessibleAttributes()
Gets all the properties of accessible element.
|
HashMap<String,Object> |
getAttributes()
Gets the attributes for this Chunk .
|
float |
getCharacterSpacing()
Gets the character spacing.
|
List<Chunk> |
getChunks()
Gets all the chunks in this element.
|
String |
getContent()
Returns the content of this Chunk .
|
Font |
getFont()
Gets the font of this Chunk .
|
float |
getHorizontalScaling()
Gets the horizontal scaling.
|
HyphenationEvent |
getHyphenation()
Returns the hyphenation (if present).
|
AccessibleElementId |
getId() |
Image |
getImage()
Returns the image.
|
PdfName |
getRole()
Gets the role of the accessible element.
|
String |
getTextExpansion() |
float |
getTextRise()
Gets the text displacement relative to the baseline.
|
float |
getWidthPoint()
Gets the width of the Chunk in points.
|
float |
getWordSpacing()
Gets the word spacing.
|
boolean |
hasAccessibleAttributes()
Checks the accessible attributes of this Chunk .
|
boolean |
hasAttributes()
Checks the attributes of this Chunk .
|
boolean |
isContent()
Checks if this element is a content object.
|
boolean |
isEmpty()
Checks is this Chunk is empty.
|
boolean |
isInline() |
boolean |
isNestable()
Checks if this element is nestable.
|
boolean |
isTabspace()
Deprecated.
|
boolean |
isWhitespace() |
boolean |
process(ElementListener listener)
Processes the element by adding it (or the different parts) to an ElementListener .
|
void |
setAccessibleAttribute(PdfName key, PdfObject value)
Set the attribute of accessible element (everything in A dictionary + Lang , Alt , ActualText , E ).
|
Chunk |
setAction(PdfAction action)
Sets an action for this Chunk .
|
Chunk |
setAnchor(String url)
Sets an anchor for this Chunk .
|
Chunk |
setAnchor(URL url)
Sets an anchor for this Chunk .
|
Chunk |
setAnnotation(PdfAnnotation annotation)
Sets a generic annotation to this Chunk .
|
void |
setAttributes(HashMap<String,Object> attributes)
Sets the attributes all at once.
|
Chunk |
setBackground(BaseColor color)
Sets the color of the background Chunk .
|
Chunk |
setBackground(BaseColor color, float extraLeft, float extraBottom, float extraRight, float extraTop)
Sets the color and the size of the background Chunk .
|
Chunk |
setCharacterSpacing(float charSpace)
Sets the character spacing.
|
void |
setFont(Font font)
Sets the font of this Chunk .
|
Chunk |
setGenericTag(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 .
|
void |
setId(AccessibleElementId id) |
Chunk |
setLineHeight(float lineheight)
Sets a line height tag.
|
Chunk |
setLocalDestination(String name)
Sets a local destination for this Chunk .
|
Chunk |
setLocalGoto(String name)
Sets a local goto for this Chunk .
|
Chunk |
setNewPage()
Sets a new page tag..
|
Chunk |
setRemoteGoto(String filename, int page)
Sets a goto for a remote destination for this Chunk .
|
Chunk |
setRemoteGoto(String filename, String name)
Sets a goto for a remote destination for this Chunk .
|
void |
setRole(PdfName role)
Sets the role of the accessiblee element.
|
Chunk |
setSkew(float alpha, float beta)
Skews the text to simulate italic and other effects.
|
Chunk |
setSplitCharacter(SplitCharacter splitCharacter)
Sets the split characters.
|
void |
setTextExpansion(String value)
Sets the textual expansion of the abbreviation or acronym.
|
Chunk |
setTextRenderMode(int mode, float strokeWidth, BaseColor strokeColor)
Sets the text rendering mode.
|
Chunk |
setTextRise(float rise)
Sets the text displacement relative to the baseline.
|
Chunk |
setUnderline(BaseColor 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.
|
Chunk |
setWordSpacing(float wordSpace)
Sets the word spacing.
|
String |
toString()
Returns the content of this Chunk .
|
int |
type()
Gets the type of the text element.
|
public static final String OBJECT_REPLACEMENT_CHARACTER
public static final Chunk NEWLINE
public static final Chunk NEXTPAGE
public static final Chunk TABBING
public static final Chunk SPACETABBING
protected StringBuffer content
protected Font font
Font
of this chunk of text.
protected HashMap<String,Object> attributes
protected PdfName role
public static final String SEPARATOR
public static final String TAB
public static final String TABSETTINGS
public static final String HSCALE
public static final String UNDERLINE
public static final String SUBSUPSCRIPT
public static final String SKEW
public static final String BACKGROUND
public static final String TEXTRENDERMODE
public static final String SPLITCHARACTER
public static final String HYPHENATION
public static final String REMOTEGOTO
public static final String LOCALGOTO
public static final String LOCALDESTINATION
public static final String GENERICTAG
public static final String LINEHEIGHT
public static final String IMAGE
public static final String ACTION
public static final String NEWPAGE
public static final String PDFANNOTATION
public static final String COLOR
public static final String ENCODING
public static final String CHAR_SPACING
public static final String WORD_SPACING
public static final String WHITESPACE
public Chunk()
public Chunk(Chunk ck)
Chunk
copy constructor.
ck
- the Chunk
to be copied
public Chunk(String content, Font font)
Font
.
content
- the content
font
- the font
public Chunk(String content)
Font
.
content
- the content
public Chunk(char c, Font font)
Font
.
c
- the content
font
- the font
public Chunk(char c)
Font
.
c
- the content
public Chunk(Image image, float offsetX, float offsetY)
Image
.
image
- the image
offsetX
- the image offset in the x direction
offsetY
- the image offset in the y direction
public Chunk(DrawInterface separator)
separator
- the drawInterface to use to draw the separator.
public Chunk(DrawInterface separator, boolean vertical)
separator
- the drawInterface to use to draw the separator.
vertical
- true if this is a vertical separator
@Deprecated public Chunk(DrawInterface separator, float tabPosition)
separator
- the drawInterface to use to draw the tab.
tabPosition
- an X coordinate that will be used as start position for the next Chunk.
@Deprecated public Chunk(DrawInterface separator, float tabPosition, boolean newline)
separator
- the drawInterface to use to draw the tab.
tabPosition
- an X coordinate that will be used as start position for the next Chunk.
newline
- if true, a newline will be added if the tabPosition has already been reached.
public Chunk(Image image, float offsetX, float offsetY, boolean changeLeading)
Image
.
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
public boolean process(ElementListener listener)
ElementListener
.
public int type()
public StringBuffer append(String string)
Chunk
.
string
- String
StringBuffer
public void setFont(Font font)
Chunk
.
font
- a Font
public Font getFont()
Chunk
.
Font
public String getContent()
Chunk
.
String
public String toString()
Chunk
.
public boolean isEmpty()
Chunk
is empty.
false
if the Chunk contains other characters than space.
public float getWidthPoint()
public boolean hasAttributes()
Chunk
.
public boolean hasAccessibleAttributes()
Chunk
.
public HashMap<String,Object> getAttributes()
Chunk
.
It may be null.
Chunk
public void setAttributes(HashMap<String,Object> attributes)
attributes
- the attributes of a Chunk
public Chunk setHorizontalScaling(float scale)
scale
- the horizontal scaling factor
Chunk
public float getHorizontalScaling()
public Chunk setUnderline(float thickness, float yPosition)
Chunk
width. Multiple call to this method will produce multiple lines.
thickness
- the absolute thickness of the line
yPosition
- the absolute y position relative to the baseline
Chunk
public Chunk setUnderline(BaseColor 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 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
Chunk
public Chunk setTextRise(float rise)
It can be used to implement sub/superscript.
rise
- the displacement in points
Chunk
public float getTextRise()
public Chunk setSkew(float alpha, float beta)
alpha=0
and beta=12
.
alpha
- the first angle in degrees
beta
- the second angle in degrees
Chunk
public Chunk setBackground(BaseColor color)
Chunk
.
color
- the color of the background
Chunk
public Chunk setBackground(BaseColor color, float extraLeft, float extraBottom, float extraRight, float extraTop)
Chunk
.
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
Chunk
public Chunk setTextRenderMode(int mode, float strokeWidth, BaseColor 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 color
Chunk
public Chunk setSplitCharacter(SplitCharacter splitCharacter)
splitCharacter
- the SplitCharacter
interface
Chunk
public Chunk setHyphenation(HyphenationEvent hyphenation)
Chunk
.
hyphenation
- the hyphenation engine
Chunk
public Chunk setRemoteGoto(String filename, String name)
Chunk
.
filename
- the file name of the destination document
name
- the name of the destination to go to
Chunk
public Chunk setRemoteGoto(String filename, int page)
Chunk
.
filename
- the file name of the destination document
page
- the page of the destination to go to. First page is 1
Chunk
public Chunk setLocalGoto(String name)
Chunk
.
There must be a local destination matching the name.
name
- the name of the destination to go to
Chunk
public Chunk setLocalDestination(String name)
Chunk
.
name
- the name for this destination
Chunk
public Chunk setGenericTag(String text)
Chunk
.
The text for this tag can be retrieved with PdfPageEvent
.
text
- the text for the tag
Chunk
public Chunk setLineHeight(float lineheight)
Chunk
public Image getImage()
public Chunk setAction(PdfAction action)
Chunk
.
action
- the action
Chunk
public Chunk setAnchor(URL url)
Chunk
.
url
- the URL
to link to
Chunk
public Chunk setAnchor(String url)
Chunk
.
url
- the url to link to
Chunk
public Chunk setNewPage()
Chunk
public Chunk setAnnotation(PdfAnnotation annotation)
Chunk
.
annotation
- the annotation
Chunk
public boolean isContent()
Element
isContent
in interface Element
Element.isContent()
public boolean isNestable()
Element
isNestable
in interface Element
Element.isNestable()
public HyphenationEvent getHyphenation()
public Chunk setCharacterSpacing(float charSpace)
charSpace
- the character spacing value
Chunk
public float getCharacterSpacing()
public Chunk setWordSpacing(float wordSpace)
wordSpace
- the word spacing value
Chunk
public float getWordSpacing()
public boolean isWhitespace()
@Deprecated public static Chunk createTabspace()
@Deprecated public static Chunk createTabspace(float spacing)
@Deprecated public boolean isTabspace()
public PdfObject getAccessibleAttribute(PdfName key)
IAccessibleElement
A
dictionary + Lang
, Alt
, ActualText
, E
).
getAccessibleAttribute
in interface IAccessibleElement
public void setAccessibleAttribute(PdfName key, PdfObject value)
IAccessibleElement
A
dictionary + Lang
, Alt
, ActualText
, E
).
setAccessibleAttribute
in interface IAccessibleElement
public HashMap<PdfName,PdfObject> getAccessibleAttributes()
IAccessibleElement
getAccessibleAttributes
in interface IAccessibleElement
public PdfName getRole()
IAccessibleElement
getRole
in interface IAccessibleElement
public void setRole(PdfName role)
IAccessibleElement
null
if you don't want to tag this element. Note that all child elements won't also be tagged.
setRole
in interface IAccessibleElement
public AccessibleElementId getId()
getId
in interface IAccessibleElement
public void setId(AccessibleElementId id)
setId
in interface IAccessibleElement
public boolean isInline()
isInline
in interface IAccessibleElement
public String getTextExpansion()
public void setTextExpansion(String value)
value
-
Copyright © 1998–2018. All rights reserved.