Table of Contents

Class ColumnText

Namespace
iTextSharp.text.pdf
Assembly
iTextSharp.LGPLv2.Core.dll

Formats text in a columnwise form. The text is bound on the left and on the right by a sequence of lines. This allows the column to have any shape, not only rectangular. Several parameters can be set like the first paragraph line indent and extra space between paragraphs. A call to the method go will return one of the following situations: the column ended or the text ended. I the column ended, a new column definition can be loaded with the method setColumns and the method go can be called again. If the text ended, more text can be loaded with addText and the method go can be called again. The only limitation is that one or more complete paragraphs must be loaded each time. Full bidirectional reordering is supported. If the run direction is PdfWriter.RUN_DIRECTION_RTL the meaning of the horizontal alignments and margins is mirrored. @author Paulo Soares (psoares@consiste.pt)

public class ColumnText
Inheritance
ColumnText
Inherited Members

Constructors

ColumnText(PdfContentByte)

Creates a ColumnText . be a template.

public ColumnText(PdfContentByte canvas)

Parameters

canvas PdfContentByte

the place where the text will be written to. Can

Fields

AR_COMPOSEDTASHKEEL

Compose the tashkeel in the ligatures.

public const int AR_COMPOSEDTASHKEEL = 4

Field Value

int

AR_LIG

Do some extra double ligatures.

public const int AR_LIG = 8

Field Value

int

ArNovowel

Eliminate the arabic vowels

public int ArNovowel

Field Value

int

BidiLine

The chunks that form the text.

protected BidiLine BidiLine

Field Value

BidiLine

Composite

protected bool Composite

Field Value

bool

CompositeColumn

protected ColumnText CompositeColumn

Field Value

ColumnText

CompositeElements

protected IList<IElement> CompositeElements

Field Value

IList<IElement>

CurrentLeading

The leading for the current line.

protected float CurrentLeading

Field Value

float

DIGITS_AN2EN

Digit shaping option: Replace Arabic-Indic digits by European digits (U+0030...U+0039).

public const int DIGITS_AN2EN = 64

Field Value

int

DIGITS_EN2AN

Digit shaping option: Replace European digits (U+0030...U+0039) by Arabic-Indic digits.

public const int DIGITS_EN2AN = 32

Field Value

int

DIGITS_EN2AN_INIT_AL

Digit shaping option: Replace European digits (U+0030...U+0039) by Arabic-Indic digits if the most recent strongly directional character is an Arabic letter (its Bidi direction value is RIGHT_TO_LEFT_ARABIC). The initial state at the start of the text is assumed to be an Arabic, letter, so European digits at the start of the text will change. Compare to DIGITS_ALEN2AN_INT_LR.

public const int DIGITS_EN2AN_INIT_AL = 128

Field Value

int

DIGITS_EN2AN_INIT_LR

Digit shaping option: Replace European digits (U+0030...U+0039) by Arabic-Indic digits if the most recent strongly directional character is an Arabic letter (its Bidi direction value is RIGHT_TO_LEFT_ARABIC). The initial state at the start of the text is assumed to be not an Arabic, letter, so European digits at the start of the text will not change. Compare to DIGITS_ALEN2AN_INIT_AL.

public const int DIGITS_EN2AN_INIT_LR = 96

Field Value

int

DIGIT_TYPE_AN

Digit type option: Use Arabic-Indic digits (U+0660...U+0669).

public const int DIGIT_TYPE_AN = 0

Field Value

int

DIGIT_TYPE_AN_EXTENDED

Digit type option: Use Eastern (Extended) Arabic-Indic digits (U+06f0...U+06f9).

public const int DIGIT_TYPE_AN_EXTENDED = 256

Field Value

int

FixedLeading

The fixed text leading.

protected float FixedLeading

Field Value

float

GlobalSpaceCharRatio

public static float GlobalSpaceCharRatio

Field Value

float

LINE_STATUS_NOLINE

The line cannot fit this column position.

protected const int LINE_STATUS_NOLINE = 2

Field Value

int

LINE_STATUS_OFFLIMITS

The line is out the column limits.

protected const int LINE_STATUS_OFFLIMITS = 1

Field Value

int

LINE_STATUS_OK

The column is valid.

protected const int LINE_STATUS_OK = 0

Field Value

int

LeftWall

The left column bound.

protected IList<float[]> LeftWall

Field Value

IList<float[]>

LeftX

protected float LeftX

Field Value

float

LineStatus

The line status when trying to fit a line to a column.

protected int LineStatus

Field Value

int

ListIdx

protected int ListIdx

Field Value

int

MaxY

Upper bound of the column.

protected float MaxY

Field Value

float

MinY

Lower bound of the column.

protected float MinY

Field Value

float

NO_MORE_COLUMN

Signals that there is no more column.

public const int NO_MORE_COLUMN = 2

Field Value

int

NO_MORE_TEXT

Signals that there is no more text available.

public const int NO_MORE_TEXT = 1

Field Value

int

RectangularMode

protected bool RectangularMode

Field Value

bool

RectangularWidth

The width of the line when the column is defined as a simple rectangle.

protected float RectangularWidth

Field Value

float

RightWall

The right column bound.

protected IList<float[]> RightWall

Field Value

IList<float[]>

RightX

protected float RightX

Field Value

float

WaitPhrase

protected Phrase WaitPhrase

Field Value

Phrase

alignment

The column Element. Default is left Element.

protected int alignment

Field Value

int

canvas

The PdfContent where the text will be written to.

protected PdfContentByte canvas

Field Value

PdfContentByte

canvases

protected PdfContentByte[] canvases

Field Value

PdfContentByte[]

descender

protected float descender

Field Value

float

extraParagraphSpace

The extra space between paragraphs.

protected float extraParagraphSpace

Field Value

float

followingIndent

The following paragraph lines indent.

protected float followingIndent

Field Value

float

indent

The first paragraph line indent.

protected float indent

Field Value

float

multipliedLeading

The text leading that is multiplied by the biggest font size in the line.

protected float multipliedLeading

Field Value

float

rightIndent

The right paragraph lines indent.

protected float rightIndent

Field Value

float

runDirection

protected int runDirection

Field Value

int

yLine

The current y line location. Text will be written at this line minus the leading.

protected float yLine

Field Value

float

Properties

AdjustFirstLine

Sets the first line adjustment. Some objects have properties, like spacing before, that behave differently if the object is the first to be written after go() or not. The first line adjustment is true by default but can be changed if several objects are to be placed one after the other in the same column calling go() several times.

public bool AdjustFirstLine { get; set; }

Property Value

bool

Alignment

Gets the Element.

public int Alignment { get; set; }

Property Value

int

the alignment

ArabicOptions

Sets the arabic shaping options. The option can be AR_NOVOWEL, AR_COMPOSEDTASHKEEL and AR_LIG.

public int ArabicOptions { get; set; }

Property Value

int

Canvas

Sets the canvas.

public PdfContentByte Canvas { get; set; }

Property Value

PdfContentByte

Canvases

Sets the canvases.

public PdfContentByte[] Canvases { get; set; }

Property Value

PdfContentByte[]

Descender

Gets the biggest descender value of the last line written.

public float Descender { get; }

Property Value

float

the biggest descender value of the last line written

ExtraParagraphSpace

Sets the extra space between paragraphs.

public float ExtraParagraphSpace { get; set; }

Property Value

float

the extra space between paragraphs

FilledWidth

Sets the real width used by the largest line. Only used to set it to zero to start another measurement.

public float FilledWidth { get; set; }

Property Value

float

FollowingIndent

Gets the following paragraph lines indent.

public float FollowingIndent { get; set; }

Property Value

float

the indent

Indent

Gets the first paragraph line indent.

public float Indent { get; set; }

Property Value

float

the indent

Leading

Gets the fixed leading

public float Leading { get; set; }

Property Value

float

the leading

LinesWritten

Gets the number of lines written.

public int LinesWritten { get; }

Property Value

int

the number of lines written

MultipliedLeading

Gets the variable leading

public float MultipliedLeading { get; }

Property Value

float

the leading

RightIndent

Gets the right paragraph lines indent.

public float RightIndent { get; set; }

Property Value

float

the indent

RunDirection

Gets the run direction.

public int RunDirection { get; set; }

Property Value

int

the run direction

SpaceCharRatio

Gets the space/character extra spacing ratio for fully justified text.

public float SpaceCharRatio { get; set; }

Property Value

float

the space/character extra spacing ratio

UseAscender

Enables/Disables adjustment of first line height based on max ascender.

public bool UseAscender { get; set; }

Property Value

bool

YLine

Gets the yLine.

public float YLine { get; set; }

Property Value

float

the yLine

Methods

AddElement(IElement)

Adds an element. Elements supported are Paragraph , List , PdfPTable , Image and Graphic . It removes all the text placed with addText() .

public void AddElement(IElement element)

Parameters

element IElement

the Element

AddText(Chunk)

Adds a Chunk to the current text array. Will not have any effect if AddElement() was called before.

public void AddText(Chunk chunk)

Parameters

chunk Chunk

the text

AddText(Phrase)

Adds a Phrase to the current text array.

public void AddText(Phrase phrase)

Parameters

phrase Phrase

the text

ClearChunks()

Clears the chunk array. A call to go() will always return NO_MORE_TEXT.

public void ClearChunks()

ConvertColumn(float[])

Converts a sequence of lines representing one of the column bounds into an internal format. Each array element will contain a float[4] representing the line x = ax + b.

protected IList<float[]> ConvertColumn(float[] cLine)

Parameters

cLine float[]

the column array

Returns

IList<float[]>

the converted array

Duplicate(ColumnText)

Creates an independent duplicated of the instance org .

public static ColumnText Duplicate(ColumnText org)

Parameters

org ColumnText

the original ColumnText

Returns

ColumnText

the duplicated

FindLimitsOneLine()

Finds the intersection between the yLine and the two column bounds. It will set the lineStatus apropriatly.

protected float[] FindLimitsOneLine()

Returns

float[]

a float[2] with the x coordinates of the intersection

FindLimitsPoint(IList<float[]>)

Finds the intersection between the yLine and the column. It will set the lineStatus apropriatly.

protected float FindLimitsPoint(IList<float[]> wall)

Parameters

wall IList<float[]>

the column to intersect

Returns

float

the x coordinate of the intersection

FindLimitsTwoLines()

Finds the intersection between the yLine , the yLine-leading and the two column bounds. It will set the lineStatus apropriatly.

protected float[] FindLimitsTwoLines()

Returns

float[]

a float[4] with the x coordinates of the intersection

GetWidth(Phrase)

Gets the width that the line will occupy after writing. Only the width of the first line is returned.

public static float GetWidth(Phrase phrase)

Parameters

phrase Phrase

the Phrase containing the line

Returns

float

the width of the line

GetWidth(Phrase, int, int)

Gets the width that the line will occupy after writing. Only the width of the first line is returned.

public static float GetWidth(Phrase phrase, int runDirection, int arabicOptions)

Parameters

phrase Phrase

the Phrase containing the line

runDirection int

the run direction

arabicOptions int

the options for the arabic shaping

Returns

float

the width of the line

Go()

Outputs the lines to the document. It is equivalent to go(false) . and/or NO_MORE_COLUMN @throws DocumentException on error

public int Go()

Returns

int

returns the result of the operation. It can be NO_MORE_TEXT

Go(bool)

Outputs the lines to the document. The output can be simulated. and/or NO_MORE_COLUMN @throws DocumentException on error

public int Go(bool simulate)

Parameters

simulate bool

true to simulate the writting to the document

Returns

int

returns the result of the operation. It can be NO_MORE_TEXT

GoComposite(bool)

protected int GoComposite(bool simulate)

Parameters

simulate bool

Returns

int

HasMoreText(int)

Checks the status variable and looks if there's still some text.

public static bool HasMoreText(int status)

Parameters

status int

Returns

bool

SetACopy(ColumnText)

Makes this instance an independent copy of org .

public ColumnText SetACopy(ColumnText org)

Parameters

org ColumnText

the original ColumnText

Returns

ColumnText

itself

SetColumns(float[], float[])

Sets the columns bounds. Each column bound is described by a float[] with the line points [x1,y1,x2,y2,...]. The array must have at least 4 elements.

public void SetColumns(float[] leftLine, float[] rightLine)

Parameters

leftLine float[]

the left column bound

rightLine float[]

the right column bound

SetLeading(float, float)

Sets the leading fixed and variable. The resultant leading will be fixedLeading+multipliedLeading*maxFontSize where maxFontSize is the size of the bigest font in the line.

public void SetLeading(float fixedLeading, float multipliedLeading)

Parameters

fixedLeading float

the fixed leading

multipliedLeading float

the variable leading

SetSimpleColumn(float, float, float, float)

Simplified method for rectangular columns.

public void SetSimpleColumn(float llx, float lly, float urx, float ury)

Parameters

llx float
lly float
urx float
ury float

SetSimpleColumn(float, float, float, float, float, int)

Simplified method for rectangular columns.

public void SetSimpleColumn(float llx, float lly, float urx, float ury, float leading, int alignment)

Parameters

llx float

the lower left x corner

lly float

the lower left y corner

urx float

the upper right x corner

ury float

the upper right y corner

leading float

the leading

alignment int

the column alignment

SetSimpleColumn(Phrase, float, float, float, float, float, int)

Simplified method for rectangular columns.

public void SetSimpleColumn(Phrase phrase, float llx, float lly, float urx, float ury, float leading, int alignment)

Parameters

phrase Phrase

a Phrase

llx float

the lower left x corner

lly float

the lower left y corner

urx float

the upper right x corner

ury float

the upper right y corner

leading float

the leading

alignment int

the column alignment

SetSimpleVars(ColumnText)

protected void SetSimpleVars(ColumnText org)

Parameters

org ColumnText

SetText(Phrase)

Replaces the current text array with this Phrase . Anything added previously with AddElement() is lost.

public void SetText(Phrase phrase)

Parameters

phrase Phrase

the text

ShowTextAligned(PdfContentByte, int, Phrase, float, float, float)

Shows a line of text. Only the first line is written.

public static void ShowTextAligned(PdfContentByte canvas, int alignment, Phrase phrase, float x, float y, float rotation)

Parameters

canvas PdfContentByte

where the text is to be written to

alignment int

the alignment

phrase Phrase

the Phrase with the text

x float

the x reference position

y float

the y reference position

rotation float

the rotation to be applied in degrees counterclockwise

ShowTextAligned(PdfContentByte, int, Phrase, float, float, float, int, int)

Shows a line of text. Only the first line is written.

public static void ShowTextAligned(PdfContentByte canvas, int alignment, Phrase phrase, float x, float y, float rotation, int runDirection, int arabicOptions)

Parameters

canvas PdfContentByte

where the text is to be written to

alignment int

the alignment. It is not influenced by the run direction

phrase Phrase

the Phrase with the text

x float

the x reference position

y float

the y reference position

rotation float

the rotation to be applied in degrees counterclockwise

runDirection int

the run direction

arabicOptions int

the options for the arabic shaping

UpdateFilledWidth(float)

Replaces the filledWidth if greater than the existing one.

public void UpdateFilledWidth(float w)

Parameters

w float

the new filledWidth if greater than the existing one

ZeroHeightElement()

Checks if the element has a height of 0. @since 2.1.2

public bool ZeroHeightElement()

Returns

bool

true or false