Class Chunk
- Namespace
- iTextSharp.text
- Assembly
- iTextSharp.LGPLv2.Core.dll
This is the smallest significant part of text that can be added to a document.
public class Chunk : IElement
- Inheritance
-
Chunk
- Implements
- Derived
- Inherited Members
Examples
Chunk chunk = new Chunk("Hello world", FontFactory.GetFont(FontFactory.COURIER, 20, Font.ITALIC, new Color(255, 0, 0))); document.Add(chunk);
Remarks
Most elements can be divided in one or more Chunks. A chunk is a string with a certain Font. all other layoutparameters should be defined in the object to which this chunk of text is added.
Constructors
Chunk()
constructors
public Chunk()
Chunk(char)
Constructs a chunk of text with a char, without specifying a Font .
public Chunk(char c)
Parameters
c
charthe content
Chunk(char, Font)
Constructs a chunk of text with a char and a certain Font .
public Chunk(char c, Font font)
Parameters
Chunk(string)
Constructs a chunk of text with a certain content, without specifying a Font.
public Chunk(string content)
Parameters
content
stringthe content
Chunk(string, Font)
Constructs a chunk of text with a certain content and a certain Font.
public Chunk(string content, Font font)
Parameters
Chunk(Chunk)
A Chunk copy constructor.
public Chunk(Chunk ck)
Parameters
ck
Chunkthe Chunk to be copied
Chunk(Image, float, float)
Constructs a chunk containing an Image.
public Chunk(Image image, float offsetX, float offsetY)
Parameters
image
Imagethe image
offsetX
floatthe image offset in the x direction
offsetY
floatthe image offset in the y direction
Chunk(Image, float, float, bool)
Constructs a chunk containing an Image.
public Chunk(Image image, float offsetX, float offsetY, bool changeLeading)
Parameters
image
Imagethe image
offsetX
floatthe image offset in the x direction
offsetY
floatthe image offset in the y direction
changeLeading
booltrue if the leading has to be adapted to the image
Chunk(IDrawInterface)
Creates a separator Chunk. Note that separator chunks can't be used in combination with tab chunks! @since 2.1.2
public Chunk(IDrawInterface separator)
Parameters
separator
IDrawInterfacethe drawInterface to use to draw the separator.
Chunk(IDrawInterface, bool)
Creates a separator Chunk. Note that separator chunks can't be used in combination with tab chunks! @since 2.1.2
public Chunk(IDrawInterface separator, bool vertical)
Parameters
separator
IDrawInterfacethe drawInterface to use to draw the separator.
vertical
booltrue if this is a vertical separator
Chunk(IDrawInterface, float)
Creates a tab Chunk. Note that separator chunks can't be used in combination with tab chunks! @since 2.1.2
public Chunk(IDrawInterface separator, float tabPosition)
Parameters
separator
IDrawInterfacethe drawInterface to use to draw the tab.
tabPosition
floatan X coordinate that will be used as start position for the next Chunk.
Chunk(IDrawInterface, float, bool)
Creates a tab Chunk. Note that separator chunks can't be used in combination with tab chunks! @since 2.1.2
public Chunk(IDrawInterface separator, float tabPosition, bool newline)
Parameters
separator
IDrawInterfacethe drawInterface to use to draw the tab.
tabPosition
floatan X coordinate that will be used as start position for the next Chunk.
newline
boolif true, a newline will be added if the tabPosition has already been reached.
Fields
ACTION
public static membervariables
public const string ACTION = "ACTION"
Field Value
BACKGROUND
Key for background.
public const string BACKGROUND = "BACKGROUND"
Field Value
COLOR
Key for color.
public const string COLOR = "COLOR"
Field Value
ENCODING
keys used in PdfChunk
public const string ENCODING = "ENCODING"
Field Value
GENERICTAG
Key for generic tag.
public const string GENERICTAG = "GENERICTAG"
Field Value
HSCALE
Key for text horizontal scaling.
public const string HSCALE = "HSCALE"
Field Value
HYPHENATION
Key for hyphenation.
public const string HYPHENATION = "HYPHENATION"
Field Value
IMAGE
Key for image.
public const string IMAGE = "IMAGE"
Field Value
LOCALDESTINATION
Key for local destination.
public const string LOCALDESTINATION = "LOCALDESTINATION"
Field Value
LOCALGOTO
Key for local goto.
public const string LOCALGOTO = "LOCALGOTO"
Field Value
NEWPAGE
Key for newpage.
public const string NEWPAGE = "NEWPAGE"
Field Value
Newline
This is a Chunk containing a newline.
public static readonly Chunk Newline
Field Value
Nextpage
This is a Chunk containing a newpage.
public static readonly Chunk Nextpage
Field Value
OBJECT_REPLACEMENT_CHARACTER
The character stand in for an image or a separator.
public const string OBJECT_REPLACEMENT_CHARACTER = ""
Field Value
PDFANNOTATION
Key for annotation.
public const string PDFANNOTATION = "PDFANNOTATION"
Field Value
REMOTEGOTO
Key for remote goto.
public const string REMOTEGOTO = "REMOTEGOTO"
Field Value
SEPARATOR
Key for drawInterface of the Separator. @since 2.1.2
public const string SEPARATOR = "SEPARATOR"
Field Value
SKEW
Key for text skewing.
public const string SKEW = "SKEW"
Field Value
SPLITCHARACTER
Key for split character.
public const string SPLITCHARACTER = "SPLITCHARACTER"
Field Value
SUBSUPSCRIPT
Key for sub/basescript.
public const string SUBSUPSCRIPT = "SUBSUPSCRIPT"
Field Value
TAB
Key for drawInterface of the tab. @since 2.1.2
public const string TAB = "TAB"
Field Value
TEXTRENDERMODE
Key for text rendering mode.
public const string TEXTRENDERMODE = "TEXTRENDERMODE"
Field Value
UNDERLINE
Key for underline.
public const string UNDERLINE = "UNDERLINE"
Field Value
attributes
Contains some of the attributes for this Chunk.
protected INullValueDictionary<string, object> attributes
Field Value
content
This is the content of this chunk of text.
protected StringBuilder content
Field Value
font
member variables
protected Font font
Field Value
Properties
Attributes
implementation of the Element-methods
public INullValueDictionary<string, object> Attributes { get; set; }
Property Value
- INullValueDictionary<string, object>
a Hashtable
Remarks
It may be null.
Chunks
Gets all the chunks in this element.
public IList<Chunk> Chunks { get; }
Property Value
Content
Returns the content of this Chunk.
public virtual string Content { get; }
Property Value
- string
a string
Font
Get/set the font of this Chunk.
public virtual Font Font { get; set; }
Property Value
- Font
a Font
HorizontalScaling
Gets the horizontal scaling.
public float HorizontalScaling { get; }
Property Value
- float
a percentage in float
Type
Gets the type of the text element.
public int Type { get; }
Property Value
- int
a type
Methods
Append(string)
appends some text to this Chunk.
public StringBuilder Append(string str)
Parameters
str
stringa string
Returns
- StringBuilder
a StringBuilder
GetHyphenation()
Returns the hyphenation (if present). @since 2.1.2
public IHyphenationEvent GetHyphenation()
Returns
GetImage()
Returns the image.
public Image GetImage()
Returns
- Image
an Image
GetTextRise()
public float GetTextRise()
Returns
GetWidthPoint()
Gets the width of the Chunk in points.
public float GetWidthPoint()
Returns
- float
a width in points
HasAttributes()
Checks the attributes of this Chunk.
public bool HasAttributes()
Returns
- bool
false if there aren't any.
IsContent()
@see com.lowagie.text.Element#isContent() @since iText 2.0.8
public bool IsContent()
Returns
IsEmpty()
Checks is this Chunk is empty.
public virtual bool IsEmpty()
Returns
- bool
false if the Chunk contains other characters than space.
IsNestable()
@see com.lowagie.text.Element#isNestable() @since iText 2.0.8
public bool IsNestable()
Returns
IsTag(string)
Checks if a given tag corresponds with this object.
public static bool IsTag(string tag)
Parameters
tag
stringthe given tag
Returns
- bool
true if the tag corresponds
Process(IElementListener)
Processes the element by adding it (or the different parts) to an IElementListener.
public bool Process(IElementListener listener)
Parameters
listener
IElementListeneran IElementListener
Returns
- bool
true if the element was processed successfully
SetAction(PdfAction)
Sets an action for this Chunk.
public Chunk SetAction(PdfAction action)
Parameters
action
PdfActionthe action
Returns
- Chunk
this Chunk
SetAnchor(string)
Sets an anchor for this Chunk.
public Chunk SetAnchor(string url)
Parameters
url
stringthe url to link to
Returns
- Chunk
this Chunk
SetAnchor(Uri)
Sets an anchor for this Chunk.
public Chunk SetAnchor(Uri url)
Parameters
url
Urithe Uri to link to
Returns
- Chunk
this Chunk
SetAnnotation(PdfAnnotation)
Sets a generic annotation to this Chunk.
public Chunk SetAnnotation(PdfAnnotation annotation)
Parameters
annotation
PdfAnnotationthe annotation
Returns
- Chunk
this Chunk
SetBackground(BaseColor)
Sets the color of the background Chunk.
public Chunk SetBackground(BaseColor color)
Parameters
color
BaseColorthe color of the background
Returns
- Chunk
this Chunk
SetBackground(BaseColor, float, float, float, float)
Sets the color and the size of the background Chunk .
public Chunk SetBackground(BaseColor color, float extraLeft, float extraBottom, float extraRight, float extraTop)
Parameters
color
BaseColorthe color of the background
extraLeft
floatincrease the size of the rectangle in the left
extraBottom
floatincrease the size of the rectangle in the bottom
extraRight
floatincrease the size of the rectangle in the right
extraTop
floatincrease the size of the rectangle in the top
Returns
- Chunk
this Chunk
SetGenericTag(string)
Sets the generic tag Chunk.
public Chunk SetGenericTag(string text)
Parameters
text
stringthe text for the tag
Returns
- Chunk
this Chunk
Remarks
The text for this tag can be retrieved with PdfPageEvent.
SetHorizontalScaling(float)
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.
public Chunk SetHorizontalScaling(float scale)
Parameters
scale
floatthe horizontal scaling factor
Returns
- Chunk
this Chunk
SetHyphenation(IHyphenationEvent)
sets the hyphenation engine to this Chunk.
public Chunk SetHyphenation(IHyphenationEvent hyphenation)
Parameters
hyphenation
IHyphenationEventthe hyphenation engine
Returns
- Chunk
this Chunk
SetLocalDestination(string)
Sets a local destination for this Chunk.
public Chunk SetLocalDestination(string name)
Parameters
name
stringthe name for this destination
Returns
- Chunk
this Chunk
SetLocalGoto(string)
Sets a local goto for this Chunk.
public Chunk SetLocalGoto(string name)
Parameters
name
stringthe name of the destination to go to
Returns
- Chunk
this Chunk
Remarks
There must be a local destination matching the name.
SetNewPage()
Sets a new page tag.
public Chunk SetNewPage()
Returns
- Chunk
this Chunk
SetRemoteGoto(string, int)
Sets a goto for a remote destination for this Chunk.
public Chunk SetRemoteGoto(string filename, int page)
Parameters
filename
stringthe file name of the destination document
page
intthe page of the destination to go to. First page is 1
Returns
- Chunk
this Chunk
SetRemoteGoto(string, string)
Sets a goto for a remote destination for this Chunk.
public Chunk SetRemoteGoto(string filename, string name)
Parameters
filename
stringthe file name of the destination document
name
stringthe name of the destination to go to
Returns
- Chunk
this Chunk
SetSkew(float, float)
Skews the text to simulate italic and other effects. Try alpha=0 and beta=12 .
public Chunk SetSkew(float alpha, float beta)
Parameters
Returns
- Chunk
this Chunk
SetSplitCharacter(ISplitCharacter)
Sets the split characters.
public Chunk SetSplitCharacter(ISplitCharacter splitCharacter)
Parameters
splitCharacter
ISplitCharacterthe SplitCharacter interface
Returns
- Chunk
this Chunk
SetTextRenderMode(int, float, BaseColor)
Sets the text rendering mode. It can outline text, simulate bold and make text invisible. PdfContentByte.TEXT_RENDER_MODE_STROKE , PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE and PdfContentByte.TEXT_RENDER_MODE_INVISIBLE . PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE .
public Chunk SetTextRenderMode(int mode, float strokeWidth, BaseColor strokeColor)
Parameters
mode
intthe text rendering mode. It can be PdfContentByte.TEXT_RENDER_MODE_FILL ,
strokeWidth
floatthe stroke line width for the modes PdfContentByte.TEXT_RENDER_MODE_STROKE and
strokeColor
BaseColorthe stroke color or null to follow the text color
Returns
- Chunk
this Chunk
SetTextRise(float)
Sets the text displacement relative to the baseline. Positive values rise the text, negative values lower the text.
public Chunk SetTextRise(float rise)
Parameters
rise
floatthe displacement in points
Returns
- Chunk
this Chunk
Remarks
It can be used to implement sub/basescript.
SetUnderline(float, float)
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.
public Chunk SetUnderline(float thickness, float yPosition)
Parameters
thickness
floatthe absolute thickness of the line
yPosition
floatthe absolute y position relative to the baseline
Returns
- Chunk
this Chunk
SetUnderline(BaseColor, float, float, float, float, int)
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. the text color PdfContentByte.LINE_CAP_BUTT, PdfContentByte.LINE_CAP_ROUND and PdfContentByte.LINE_CAP_PROJECTING_SQUARE
public Chunk SetUnderline(BaseColor color, float thickness, float thicknessMul, float yPosition, float yPositionMul, int cap)
Parameters
color
BaseColorthe color of the line or null to follow
thickness
floatthe absolute thickness of the line
thicknessMul
floatthe thickness multiplication factor with the font size
yPosition
floatthe absolute y position relative to the baseline
yPositionMul
floatthe position multiplication factor with the font size
cap
intthe end line cap. Allowed values are
Returns
- Chunk
this Chunk
ToString()
methods
public override string ToString()