Table of Contents

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 char

the content

Chunk(char, Font)

Constructs a chunk of text with a char and a certain Font .

public Chunk(char c, Font font)

Parameters

c char

the content

font Font

the font

Chunk(string)

Constructs a chunk of text with a certain content, without specifying a Font.

public Chunk(string content)

Parameters

content string

the content

Chunk(string, Font)

Constructs a chunk of text with a certain content and a certain Font.

public Chunk(string content, Font font)

Parameters

content string

the content

font Font

the font

Chunk(Chunk)

A Chunk copy constructor.

public Chunk(Chunk ck)

Parameters

ck Chunk

the Chunk to be copied

Chunk(Image, float, float)

Constructs a chunk containing an Image.

public Chunk(Image image, float offsetX, float offsetY)

Parameters

image Image

the image

offsetX float

the image offset in the x direction

offsetY float

the 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 Image

the image

offsetX float

the image offset in the x direction

offsetY float

the image offset in the y direction

changeLeading bool

true 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 IDrawInterface

the 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 IDrawInterface

the drawInterface to use to draw the separator.

vertical bool

true 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 IDrawInterface

the drawInterface to use to draw the tab.

tabPosition float

an 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 IDrawInterface

the drawInterface to use to draw the tab.

tabPosition float

an X coordinate that will be used as start position for the next Chunk.

newline bool

if 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

string

BACKGROUND

Key for background.

public const string BACKGROUND = "BACKGROUND"

Field Value

string

COLOR

Key for color.

public const string COLOR = "COLOR"

Field Value

string

ENCODING

keys used in PdfChunk

public const string ENCODING = "ENCODING"

Field Value

string

GENERICTAG

Key for generic tag.

public const string GENERICTAG = "GENERICTAG"

Field Value

string

HSCALE

Key for text horizontal scaling.

public const string HSCALE = "HSCALE"

Field Value

string

HYPHENATION

Key for hyphenation.

public const string HYPHENATION = "HYPHENATION"

Field Value

string

IMAGE

Key for image.

public const string IMAGE = "IMAGE"

Field Value

string

LOCALDESTINATION

Key for local destination.

public const string LOCALDESTINATION = "LOCALDESTINATION"

Field Value

string

LOCALGOTO

Key for local goto.

public const string LOCALGOTO = "LOCALGOTO"

Field Value

string

NEWPAGE

Key for newpage.

public const string NEWPAGE = "NEWPAGE"

Field Value

string

Newline

This is a Chunk containing a newline.

public static readonly Chunk Newline

Field Value

Chunk

Nextpage

This is a Chunk containing a newpage.

public static readonly Chunk Nextpage

Field Value

Chunk

OBJECT_REPLACEMENT_CHARACTER

The character stand in for an image or a separator.

public const string OBJECT_REPLACEMENT_CHARACTER = ""

Field Value

string

PDFANNOTATION

Key for annotation.

public const string PDFANNOTATION = "PDFANNOTATION"

Field Value

string

REMOTEGOTO

Key for remote goto.

public const string REMOTEGOTO = "REMOTEGOTO"

Field Value

string

SEPARATOR

Key for drawInterface of the Separator. @since 2.1.2

public const string SEPARATOR = "SEPARATOR"

Field Value

string

SKEW

Key for text skewing.

public const string SKEW = "SKEW"

Field Value

string

SPLITCHARACTER

Key for split character.

public const string SPLITCHARACTER = "SPLITCHARACTER"

Field Value

string

SUBSUPSCRIPT

Key for sub/basescript.

public const string SUBSUPSCRIPT = "SUBSUPSCRIPT"

Field Value

string

TAB

Key for drawInterface of the tab. @since 2.1.2

public const string TAB = "TAB"

Field Value

string

TEXTRENDERMODE

Key for text rendering mode.

public const string TEXTRENDERMODE = "TEXTRENDERMODE"

Field Value

string

UNDERLINE

Key for underline.

public const string UNDERLINE = "UNDERLINE"

Field Value

string

attributes

Contains some of the attributes for this Chunk.

protected INullValueDictionary<string, object> attributes

Field Value

INullValueDictionary<string, object>

content

This is the content of this chunk of text.

protected StringBuilder content

Field Value

StringBuilder

font

member variables

protected Font font

Field Value

Font

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

IList<Chunk>

an ArrayList

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 string

a string

Returns

StringBuilder

a StringBuilder

GetHyphenation()

Returns the hyphenation (if present). @since 2.1.2

public IHyphenationEvent GetHyphenation()

Returns

IHyphenationEvent

GetImage()

Returns the image.

public Image GetImage()

Returns

Image

an Image

GetTextRise()

public float GetTextRise()

Returns

float

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

bool

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

bool

IsTag(string)

Checks if a given tag corresponds with this object.

public static bool IsTag(string tag)

Parameters

tag string

the 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 IElementListener

an 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 PdfAction

the action

Returns

Chunk

this Chunk

SetAnchor(string)

Sets an anchor for this Chunk.

public Chunk SetAnchor(string url)

Parameters

url string

the url to link to

Returns

Chunk

this Chunk

SetAnchor(Uri)

Sets an anchor for this Chunk.

public Chunk SetAnchor(Uri url)

Parameters

url Uri

the Uri to link to

Returns

Chunk

this Chunk

SetAnnotation(PdfAnnotation)

Sets a generic annotation to this Chunk.

public Chunk SetAnnotation(PdfAnnotation annotation)

Parameters

annotation PdfAnnotation

the annotation

Returns

Chunk

this Chunk

SetBackground(BaseColor)

Sets the color of the background Chunk.

public Chunk SetBackground(BaseColor color)

Parameters

color BaseColor

the 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 BaseColor

the color of the background

extraLeft float

increase the size of the rectangle in the left

extraBottom float

increase the size of the rectangle in the bottom

extraRight float

increase the size of the rectangle in the right

extraTop float

increase 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 string

the 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 float

the horizontal scaling factor

Returns

Chunk

this Chunk

SetHyphenation(IHyphenationEvent)

sets the hyphenation engine to this Chunk.

public Chunk SetHyphenation(IHyphenationEvent hyphenation)

Parameters

hyphenation IHyphenationEvent

the hyphenation engine

Returns

Chunk

this Chunk

SetLocalDestination(string)

Sets a local destination for this Chunk.

public Chunk SetLocalDestination(string name)

Parameters

name string

the name for this destination

Returns

Chunk

this Chunk

SetLocalGoto(string)

Sets a local goto for this Chunk.

public Chunk SetLocalGoto(string name)

Parameters

name string

the 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 string

the file name of the destination document

page int

the 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 string

the file name of the destination document

name string

the 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

alpha float

the first angle in degrees

beta float

the second angle in degrees

Returns

Chunk

this Chunk

SetSplitCharacter(ISplitCharacter)

Sets the split characters.

public Chunk SetSplitCharacter(ISplitCharacter splitCharacter)

Parameters

splitCharacter ISplitCharacter

the 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 int

the text rendering mode. It can be PdfContentByte.TEXT_RENDER_MODE_FILL ,

strokeWidth float

the stroke line width for the modes PdfContentByte.TEXT_RENDER_MODE_STROKE and

strokeColor BaseColor

the 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 float

the 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 float

the absolute thickness of the line

yPosition float

the 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 BaseColor

the color of the line or null to follow

thickness float

the absolute thickness of the line

thicknessMul float

the thickness multiplication factor with the font size

yPosition float

the absolute y position relative to the baseline

yPositionMul float

the position multiplication factor with the font size

cap int

the end line cap. Allowed values are

Returns

Chunk

this Chunk

ToString()

methods

public override string ToString()

Returns

string