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
PdfContentBytethe 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
AR_LIG
Do some extra double ligatures.
public const int AR_LIG = 8
Field Value
ArNovowel
Eliminate the arabic vowels
public int ArNovowel
Field Value
BidiLine
The chunks that form the text.
protected BidiLine BidiLine
Field Value
Composite
protected bool Composite
Field Value
CompositeColumn
protected ColumnText CompositeColumn
Field Value
CompositeElements
protected IList<IElement> CompositeElements
Field Value
CurrentLeading
The leading for the current line.
protected float CurrentLeading
Field Value
DIGITS_AN2EN
Digit shaping option: Replace Arabic-Indic digits by European digits (U+0030...U+0039).
public const int DIGITS_AN2EN = 64
Field Value
DIGITS_EN2AN
Digit shaping option: Replace European digits (U+0030...U+0039) by Arabic-Indic digits.
public const int DIGITS_EN2AN = 32
Field Value
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
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
DIGIT_TYPE_AN
Digit type option: Use Arabic-Indic digits (U+0660...U+0669).
public const int DIGIT_TYPE_AN = 0
Field Value
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
FixedLeading
The fixed text leading.
protected float FixedLeading
Field Value
GlobalSpaceCharRatio
public static float GlobalSpaceCharRatio
Field Value
LINE_STATUS_NOLINE
The line cannot fit this column position.
protected const int LINE_STATUS_NOLINE = 2
Field Value
LINE_STATUS_OFFLIMITS
The line is out the column limits.
protected const int LINE_STATUS_OFFLIMITS = 1
Field Value
LINE_STATUS_OK
The column is valid.
protected const int LINE_STATUS_OK = 0
Field Value
LeftWall
The left column bound.
protected IList<float[]> LeftWall
Field Value
LeftX
protected float LeftX
Field Value
LineStatus
The line status when trying to fit a line to a column.
protected int LineStatus
Field Value
ListIdx
protected int ListIdx
Field Value
MaxY
Upper bound of the column.
protected float MaxY
Field Value
MinY
Lower bound of the column.
protected float MinY
Field Value
NO_MORE_COLUMN
Signals that there is no more column.
public const int NO_MORE_COLUMN = 2
Field Value
NO_MORE_TEXT
Signals that there is no more text available.
public const int NO_MORE_TEXT = 1
Field Value
RectangularMode
protected bool RectangularMode
Field Value
RectangularWidth
The width of the line when the column is defined as a simple rectangle.
protected float RectangularWidth
Field Value
RightWall
The right column bound.
protected IList<float[]> RightWall
Field Value
RightX
protected float RightX
Field Value
WaitPhrase
protected Phrase WaitPhrase
Field Value
alignment
The column Element. Default is left Element.
protected int alignment
Field Value
canvas
The PdfContent where the text will be written to.
protected PdfContentByte canvas
Field Value
canvases
protected PdfContentByte[] canvases
Field Value
descender
protected float descender
Field Value
extraParagraphSpace
The extra space between paragraphs.
protected float extraParagraphSpace
Field Value
followingIndent
The following paragraph lines indent.
protected float followingIndent
Field Value
indent
The first paragraph line indent.
protected float indent
Field Value
multipliedLeading
The text leading that is multiplied by the biggest font size in the line.
protected float multipliedLeading
Field Value
rightIndent
The right paragraph lines indent.
protected float rightIndent
Field Value
runDirection
protected int runDirection
Field Value
yLine
The current y line location. Text will be written at this line minus the leading.
protected float yLine
Field Value
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
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
Canvas
Sets the canvas.
public PdfContentByte Canvas { get; set; }
Property Value
Canvases
Sets the canvases.
public PdfContentByte[] Canvases { get; set; }
Property Value
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
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
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
IElementthe 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
Chunkthe text
AddText(Phrase)
Adds a Phrase to the current text array.
public void AddText(Phrase phrase)
Parameters
phrase
Phrasethe 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
Duplicate(ColumnText)
Creates an independent duplicated of the instance org .
public static ColumnText Duplicate(ColumnText org)
Parameters
org
ColumnTextthe 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
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
Phrasethe 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
Phrasethe Phrase containing the line
runDirection
intthe run direction
arabicOptions
intthe 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
booltrue 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
HasMoreText(int)
Checks the status variable and looks if there's still some text.
public static bool HasMoreText(int status)
Parameters
status
int
Returns
SetACopy(ColumnText)
Makes this instance an independent copy of org .
public ColumnText SetACopy(ColumnText org)
Parameters
org
ColumnTextthe 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
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
SetSimpleColumn(float, float, float, float)
Simplified method for rectangular columns.
public void SetSimpleColumn(float llx, float lly, float urx, float ury)
Parameters
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
floatthe lower left x corner
lly
floatthe lower left y corner
urx
floatthe upper right x corner
ury
floatthe upper right y corner
leading
floatthe leading
alignment
intthe 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
Phrasea Phrase
llx
floatthe lower left x corner
lly
floatthe lower left y corner
urx
floatthe upper right x corner
ury
floatthe upper right y corner
leading
floatthe leading
alignment
intthe 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
Phrasethe 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
PdfContentBytewhere the text is to be written to
alignment
intthe alignment
phrase
Phrasethe Phrase with the text
x
floatthe x reference position
y
floatthe y reference position
rotation
floatthe 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
PdfContentBytewhere the text is to be written to
alignment
intthe alignment. It is not influenced by the run direction
phrase
Phrasethe Phrase with the text
x
floatthe x reference position
y
floatthe y reference position
rotation
floatthe rotation to be applied in degrees counterclockwise
runDirection
intthe run direction
arabicOptions
intthe options for the arabic shaping
UpdateFilledWidth(float)
Replaces the filledWidth if greater than the existing one.
public void UpdateFilledWidth(float w)
Parameters
w
floatthe 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