Class Chunk
- java.lang.Object
-
- com.gitlab.pdftk_java.com.lowagie.text.Chunk
-
- All Implemented Interfaces:
Element,MarkupAttributes
public class Chunk extends Object implements Element, MarkupAttributes
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 aStringwith a certainFont. all other layoutparameters 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
Fields Modifier and Type Field Description static StringACTIONKey for Action.protected HashMapattributesContains some of the attributes for this Chunk.static StringBACKGROUNDKey for background.static StringCOLORKey for color.protected StringBuffercontentThis is the content of this chunk of text.static StringENCODINGKey for encoding.protected FontfontThis is theFontof this chunk of text.static StringGENERICTAGKey for generic tag.static StringHSCALEKey for text horizontal scaling.static StringHYPHENATIONKey for hyphenation.static StringIMAGEKey for image.static StringLOCALDESTINATIONKey for local destination.static StringLOCALGOTOKey for local goto.protected PropertiesmarkupAttributesContains extra markupAttributesstatic ChunkNEWLINEThis is a Chunk containing a newline.static StringNEWPAGEKey for newpage.static ChunkNEXTPAGEThis is a Chunk containing a newpage.static StringOBJECT_REPLACEMENT_CHARACTERThe character stand in for an image.static StringPDFANNOTATIONKey for annotation.static StringREMOTEGOTOKey for remote goto.static StringSKEWKey for text skewing.static StringSPLITCHARACTERKey for split character.static StringSUBSUPSCRIPTKey for sub/superscript.static StringTEXTRENDERMODEKey for text rendering mode.static StringUNDERLINEKey for underline.-
Fields inherited from interface com.gitlab.pdftk_java.com.lowagie.text.Element
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
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedChunk()Empty constructor.Chunk(char c)Constructs a chunk of text with a char, without specifying aFont.Chunk(char c, Font font)Constructs a chunk of text with a char and a certainFont.Chunk(String content)Constructs a chunk of text with a certain content, without specifying aFont.Chunk(String content, Font font)Constructs a chunk of text with a certain content and a certainFont.Chunk(Properties attributes)Returns aChunkthat has been constructed taking in account the value of some attributes .
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Object[][]addToArray(Object[][] original, Object[] item)Utility method to extend an array.StringBufferappend(String string)appends some text to thisChunk.Stringcontent()Returns the content of thisChunk.Fontfont()Gets the font of thisChunk.HashMapgetAttributes()Gets the attributes for thisChunk.ArrayListgetChunks()Gets all the chunks in this element.FontgetFont()floatgetHorizontalScaling()Gets the horizontal scaling.static SetgetKeySet(Hashtable table)Gets the keys of a HashtableStringgetMarkupAttribute(String name)Returns the value of the specified attribute.SetgetMarkupAttributeNames()Returns aSetofStringattribute names for theMarkupAttributesimplementor.PropertiesgetMarkupAttributes()Return aProperties-object containing all the markupAttributes.floatgetTextRise()Gets the text displacement relatiev to the baseline.floatgetWidthPoint()Gets the width of the Chunk in points.booleanhasAttributes()Checks the attributes of thisChunk.booleanisEmpty()Checks is thisChunkis empty.static booleanisTag(String tag)Checks if a given tag corresponds with this object.booleanprocess(ElementListener listener)Processes the element by adding it (or the different parts) to anElementListener.ChunksetAction(PdfAction action)Sets an action for thisChunk.ChunksetAnchor(String url)Sets an anchor for thisChunk.ChunksetAnchor(URL url)Sets an anchor for thisChunk.ChunksetAnnotation(PdfAnnotation annotation)Sets a generic annotation to thisChunk.ChunksetBackground(Color color)Sets the color of the backgroundChunk.ChunksetBackground(Color color, float extraLeft, float extraBottom, float extraRight, float extraTop)Sets the color and the size of the backgroundChunk.voidsetFont(Font font)Sets the font of thisChunk.ChunksetGenericTag(String text)Sets the generic tagChunk.ChunksetHorizontalScaling(float scale)Sets the text horizontal scaling.ChunksetHyphenation(HyphenationEvent hyphenation)sets the hyphenation engine to thisChunk.ChunksetLocalDestination(String name)Sets a local destination for thisChunk.ChunksetLocalGoto(String name)Sets a local goto for thisChunk.voidsetMarkupAttribute(String name, String value)Sets the specified attribute.voidsetMarkupAttributes(Properties markupAttributes)Sets the markupAttributes.ChunksetNewPage()Sets a new page tag..ChunksetRemoteGoto(String filename, int page)Sets a goto for a remote destination for thisChunk.ChunksetRemoteGoto(String filename, String name)Sets a goto for a remote destination for thisChunk.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 thisChunk.inttype()Gets the type of the text element.
-
-
-
Field Detail
-
OBJECT_REPLACEMENT_CHARACTER
public static final String OBJECT_REPLACEMENT_CHARACTER
The character stand in for an image.- See Also:
- Constant Field Values
-
NEWLINE
public static final Chunk NEWLINE
This is a Chunk containing a newline.
-
NEXTPAGE
public static final Chunk NEXTPAGE
This is a Chunk containing a newpage.
-
SUBSUPSCRIPT
public static final String SUBSUPSCRIPT
Key for sub/superscript.- See Also:
- Constant Field Values
-
UNDERLINE
public static final String UNDERLINE
Key for underline.- See Also:
- Constant Field Values
-
COLOR
public static final String COLOR
Key for color.- See Also:
- Constant Field Values
-
ENCODING
public static final String ENCODING
Key for encoding.- See Also:
- Constant Field Values
-
REMOTEGOTO
public static final String REMOTEGOTO
Key for remote goto.- See Also:
- Constant Field Values
-
LOCALGOTO
public static final String LOCALGOTO
Key for local goto.- See Also:
- Constant Field Values
-
LOCALDESTINATION
public static final String LOCALDESTINATION
Key for local destination.- See Also:
- Constant Field Values
-
IMAGE
public static final String IMAGE
Key for image.- See Also:
- Constant Field Values
-
GENERICTAG
public static final String GENERICTAG
Key for generic tag.- See Also:
- Constant Field Values
-
NEWPAGE
public static final String NEWPAGE
Key for newpage.- See Also:
- Constant Field Values
-
SPLITCHARACTER
public static final String SPLITCHARACTER
Key for split character.- See Also:
- Constant Field Values
-
ACTION
public static final String ACTION
Key for Action.- See Also:
- Constant Field Values
-
BACKGROUND
public static final String BACKGROUND
Key for background.- See Also:
- Constant Field Values
-
PDFANNOTATION
public static final String PDFANNOTATION
Key for annotation.- See Also:
- Constant Field Values
-
HYPHENATION
public static final String HYPHENATION
Key for hyphenation.- See Also:
- Constant Field Values
-
TEXTRENDERMODE
public static final String TEXTRENDERMODE
Key for text rendering mode.- See Also:
- Constant Field Values
-
SKEW
public static final String SKEW
Key for text skewing.- See Also:
- Constant Field Values
-
HSCALE
public static final String HSCALE
Key for text horizontal scaling.- See Also:
- Constant Field Values
-
content
protected StringBuffer content
This is the content of this chunk of text.
-
font
protected Font font
This is theFontof this chunk of text.
-
attributes
protected HashMap attributes
Contains some of the attributes for this Chunk.
-
markupAttributes
protected Properties markupAttributes
Contains extra markupAttributes
-
-
Constructor Detail
-
Chunk
protected Chunk()
Empty constructor.
-
Chunk
public Chunk(String content, Font font)
Constructs a chunk of text with a certain content and a certainFont.- Parameters:
content- the contentfont- the font
-
Chunk
public Chunk(String content)
Constructs a chunk of text with a certain content, without specifying aFont.- Parameters:
content- the content
-
Chunk
public Chunk(char c, Font font)Constructs a chunk of text with a char and a certainFont.- Parameters:
c- the contentfont- the font
-
Chunk
public Chunk(char c)
Constructs a chunk of text with a char, without specifying aFont.- Parameters:
c- the content
-
Chunk
public Chunk(Properties attributes)
Returns aChunkthat has been constructed taking in account the value of some attributes .- Parameters:
attributes- Some attributes
-
-
Method Detail
-
process
public boolean process(ElementListener listener)
Processes the element by adding it (or the different parts) to anElementListener.
-
type
public int type()
Gets the type of the text element.
-
getChunks
public ArrayList getChunks()
Gets all the chunks in this element.
-
append
public StringBuffer append(String string)
appends some text to thisChunk.- Parameters:
string-String- Returns:
- a
StringBuffer
-
font
public Font font()
Gets the font of thisChunk.- Returns:
- a
Font
-
getFont
public Font getFont()
-
setFont
public void setFont(Font font)
Sets the font of thisChunk.- Parameters:
font- aFont
-
content
public String content()
Returns the content of thisChunk.- Returns:
- a
String
-
toString
public String toString()
Returns the content of thisChunk.
-
isEmpty
public boolean isEmpty()
Checks is thisChunkis empty.- Returns:
falseif the Chunk contains other characters than space.
-
getWidthPoint
public float getWidthPoint()
Gets the width of the Chunk in points.- Returns:
- a width in points
-
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
-
getTextRise
public float getTextRise()
Gets the text displacement relatiev to the baseline.- Returns:
- a displacement in points
-
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 bePdfContentByte.TEXT_RENDER_MODE_FILL,PdfContentByte.TEXT_RENDER_MODE_STROKE,PdfContentByte.TEXT_RENDER_MODE_FILL_STROKEandPdfContentByte.TEXT_RENDER_MODE_INVISIBLE.strokeWidth- the stroke line width for the modesPdfContentByte.TEXT_RENDER_MODE_STROKEandPdfContentByte.TEXT_RENDER_MODE_FILL_STROKE.strokeColor- the stroke color ornullto follow the text color- Returns:
- this
Chunk
-
setSkew
public Chunk setSkew(float alpha, float beta)
Skews the text to simulate italic and other effects. Tryalpha=0andbeta=12.- Parameters:
alpha- the first angle in degreesbeta- the second angle in degrees- 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
-
getHorizontalScaling
public float getHorizontalScaling()
Gets the horizontal scaling.- Returns:
- a percentage in float
-
setAction
public Chunk setAction(PdfAction action)
Sets an action for thisChunk.- Parameters:
action- the action- Returns:
- this
Chunk
-
setAnchor
public Chunk setAnchor(URL url)
Sets an anchor for thisChunk.- Parameters:
url- theURLto link to- Returns:
- this
Chunk
-
setAnchor
public Chunk setAnchor(String url)
Sets an anchor for thisChunk.- Parameters:
url- the url to link to- Returns:
- this
Chunk
-
setLocalGoto
public Chunk setLocalGoto(String name)
Sets a local goto for thisChunk.There must be a local destination matching the name.
- Parameters:
name- the name of the destination to go to- Returns:
- this
Chunk
-
setBackground
public Chunk setBackground(Color color)
Sets the color of the backgroundChunk.- 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 backgroundChunk.- Parameters:
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- 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 theChunkwidth. Multiple call to this method will produce multiple lines.- Parameters:
thickness- the absolute thickness of the lineyPosition- 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 theChunkwidth. Multiple call to this method will produce multiple lines.- Parameters:
color- the color of the line ornullto 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- Returns:
- this
Chunk
-
addToArray
public static Object[][] addToArray(Object[][] original, Object[] item)
Utility method to extend an array.- Parameters:
original- the original array ornullitem- the item to be added to the array- Returns:
- a new array with the item appended
-
setAnnotation
public Chunk setAnnotation(PdfAnnotation annotation)
Sets a generic annotation to thisChunk.- Parameters:
annotation- the annotation- Returns:
- this
Chunk
-
setHyphenation
public Chunk setHyphenation(HyphenationEvent hyphenation)
sets the hyphenation engine to thisChunk.- Parameters:
hyphenation- the hyphenation engine- Returns:
- this
Chunk
-
setRemoteGoto
public Chunk setRemoteGoto(String filename, String name)
Sets a goto for a remote destination for thisChunk.- Parameters:
filename- the file name of the destination documentname- 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 thisChunk.- Parameters:
filename- the file name of the destination documentpage- the page of the destination to go to. First page is 1- Returns:
- this
Chunk
-
setLocalDestination
public Chunk setLocalDestination(String name)
Sets a local destination for thisChunk.- Parameters:
name- the name for this destination- Returns:
- this
Chunk
-
setGenericTag
public Chunk setGenericTag(String text)
Sets the generic tagChunk.The text for this tag can be retrieved with
PdfPageEvent.- Parameters:
text- the text for the tag- Returns:
- this
Chunk
-
setSplitCharacter
public Chunk setSplitCharacter(SplitCharacter splitCharacter)
Sets the split characters.- Parameters:
splitCharacter- theSplitCharacterinterface- Returns:
- this
Chunk
-
setNewPage
public Chunk setNewPage()
Sets a new page tag..- Returns:
- this
Chunk
-
getAttributes
public HashMap getAttributes()
Gets the attributes for thisChunk.It may be null.
- Returns:
- the attributes for this
Chunk
-
hasAttributes
public boolean hasAttributes()
Checks the attributes of thisChunk.- Returns:
- false if there aren't any.
-
isTag
public static boolean isTag(String tag)
Checks if a given tag corresponds with this object.- Parameters:
tag- the given tag- Returns:
- true if the tag corresponds
-
setMarkupAttribute
public void setMarkupAttribute(String name, String value)
Description copied from interface:MarkupAttributesSets the specified attribute.- Specified by:
setMarkupAttributein interfaceMarkupAttributes- Parameters:
name-Stringattribute name.value-Stringattribute value.- See Also:
MarkupAttributes.setMarkupAttribute(java.lang.String, java.lang.String)
-
setMarkupAttributes
public void setMarkupAttributes(Properties markupAttributes)
Description copied from interface:MarkupAttributesSets the markupAttributes.- Specified by:
setMarkupAttributesin interfaceMarkupAttributes- Parameters:
markupAttributes- aProperties-object containing markupattributes- See Also:
MarkupAttributes.setMarkupAttributes(java.util.Properties)
-
getMarkupAttribute
public String getMarkupAttribute(String name)
Description copied from interface:MarkupAttributesReturns the value of the specified attribute.- Specified by:
getMarkupAttributein interfaceMarkupAttributes- Parameters:
name-Stringattribute name.- Returns:
String.- See Also:
MarkupAttributes.getMarkupAttribute(java.lang.String)
-
getMarkupAttributeNames
public Set getMarkupAttributeNames()
Description copied from interface:MarkupAttributesReturns aSetofStringattribute names for theMarkupAttributesimplementor.- Specified by:
getMarkupAttributeNamesin interfaceMarkupAttributes- Returns:
Set.- See Also:
MarkupAttributes.getMarkupAttributeNames()
-
getMarkupAttributes
public Properties getMarkupAttributes()
Description copied from interface:MarkupAttributesReturn aProperties-object containing all the markupAttributes.- Specified by:
getMarkupAttributesin interfaceMarkupAttributes- Returns:
Properties- See Also:
MarkupAttributes.getMarkupAttributes()
-
-