com.lowagie.text.pdf
Class MultiColumnText
java.lang.Object
com.lowagie.text.pdf.MultiColumnText
- Element
public class MultiColumnText
extends java.lang.Object
Formats content into one or more columns bounded by a
rectangle. The columns may be simple rectangles or
more complicated shapes. Add all of the columns before
adding content. Column continuation is supported. A MultiColumnText object may be added to
a document using Document.add
.
static float | AUTOMATIC - special constant for automatic calculation of height
|
private ArrayList | columnDefs - Array of
ColumnDef objects used to define the columns
|
private ColumnText | columnText - ColumnText object used to do all the real work.
|
private boolean | columnsRightToLeft
|
private int | currentColumn
|
private float | desiredHeight - total desiredHeight of columns.
|
private PdfDocument | document
|
private float | nextY
|
private boolean | overflow - true if all the text could not be written out due to height restriction
|
private float | pageBottom - used to store the y position of the bottom of the page
|
private boolean | simple - true if all columns are simple (rectangular)
|
private float | top - Top of the columns - y position on starting page.
|
private float | totalHeight - total height of element written out so far
|
ALIGN_BASELINE , ALIGN_BOTTOM , ALIGN_CENTER , ALIGN_JUSTIFIED , ALIGN_JUSTIFIED_ALL , ALIGN_LEFT , ALIGN_MIDDLE , ALIGN_RIGHT , ALIGN_TOP , ALIGN_UNDEFINED , ANCHOR , ANNOTATION , AUTHOR , CCITTG3_1D , CCITTG3_2D , CCITTG4 , CCITT_BLACKIS1 , CCITT_ENCODEDBYTEALIGN , CCITT_ENDOFBLOCK , CCITT_ENDOFLINE , 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 |
void | addColumn(float[] left, float[] right) - Add a new column.
|
void | addElement(Element element) - Add an element to be rendered in a column.
|
void | addRegularColumns(float left, float right, float gutterWidth, int numColumns) - Add the specified number of evenly spaced rectangular columns.
|
void | addSimpleColumn(float left, float right) - Add a simple rectangular column with specified left
and right x position boundaries.
|
ArrayList | getChunks() - Returns null - not used
|
private float | getColumnBottom() - Calculates the appropriate y position for the bottom
of the columns on this page.
|
int | getCurrentColumn() - Gets the current column.
|
private float | getHeight(float[] left, float[] right) - Figure out the height of a column from the border extents
|
boolean | isOverflow() - Indicates that all of the text did not fit in the
specified height.
|
private void | newPage()
|
void | nextColumn() - Moves the text insertion point to the beginning of the next column, issuing a page break if
needed.
|
boolean | process(ElementListener listener) - Processes the element by adding it to an
ElementListener .
|
void | resetCurrentColumn() - Resets the current column.
|
void | setColumnsRightToLeft(boolean direction) - Sets the direction of the columns.
|
boolean | shiftCurrentColumn() - Shifts the current column.
|
int | type() - Gets the type of the text element.
|
void | useColumnParams(ColumnText sourceColumn) - Copy the parameters from the specified ColumnText to use
when rendering.
|
float | write(PdfContentByte canvas, PdfDocument document, float documentY) - Write out the columns.
|
AUTOMATIC
public static final float AUTOMATIC
special constant for automatic calculation of height
columnDefs
private ArrayList columnDefs
Array of ColumnDef
objects used to define the columns
columnText
private ColumnText columnText
ColumnText object used to do all the real work. This same object is used for all columns
columnsRightToLeft
private boolean columnsRightToLeft
currentColumn
private int currentColumn
desiredHeight
private float desiredHeight
total desiredHeight of columns. If AUTOMATIC
, this means fill pages until done.
This may be larger than one page
overflow
private boolean overflow
true if all the text could not be written out due to height restriction
pageBottom
private float pageBottom
used to store the y position of the bottom of the page
simple
private boolean simple
true if all columns are simple (rectangular)
top
private float top
Top of the columns - y position on starting page.
If AUTOMATIC
, it means current y position when added to document
totalHeight
private float totalHeight
total height of element written out so far
MultiColumnText
public MultiColumnText()
Default constructor. Sets height to AUTOMATIC
.
Columns will repeat on each page as necessary to accomodate content length.
MultiColumnText
public MultiColumnText(float height)
Construct a MultiColumnText container of the specified height.
If height is AUTOMATIC
, fill complete pages until done.
If a specific height is used, it may span one or more pages.
addColumn
public void addColumn(float[] left,
float[] right)
Add a new column. The parameters are limits for each column
wall in the format of a sequence of points (x1,y1,x2,y2,...).
left
- limits for left columnright
- limits for right column
addElement
public void addElement(Element element)
throws DocumentException
Add an element to be rendered in a column.
Note that you can only add a
Phrase
or a
Chunk
if the columns are
not all simple. This is an underlying restriction in
ColumnText
addRegularColumns
public void addRegularColumns(float left,
float right,
float gutterWidth,
int numColumns)
Add the specified number of evenly spaced rectangular columns.
Columns will be seperated by the specified gutterWidth.
left
- left boundary of first columnright
- right boundary of last columngutterWidth
- width of gutter spacing between columnsnumColumns
- number of columns to add
addSimpleColumn
public void addSimpleColumn(float left,
float right)
Add a simple rectangular column with specified left
and right x position boundaries.
left
- left boundaryright
- right boundary
getChunks
public ArrayList getChunks()
Returns null - not used
- getChunks in interface Element
getColumnBottom
private float getColumnBottom()
Calculates the appropriate y position for the bottom
of the columns on this page.
- the y position of the bottom of the columns
getCurrentColumn
public int getCurrentColumn()
Gets the current column.
getHeight
private float getHeight(float[] left,
float[] right)
Figure out the height of a column from the border extents
left
- left borderright
- right border
isOverflow
public boolean isOverflow()
Indicates that all of the text did not fit in the
specified height. Note that isOverflow will return
false before the MultiColumnText object has been
added to the document. It will always be false if
the height is AUTOMATIC.
- true if there is still space left in the column
nextColumn
public void nextColumn()
throws DocumentException
Moves the text insertion point to the beginning of the next column, issuing a page break if
needed.
process
public boolean process(ElementListener listener)
Processes the element by adding it to an
ElementListener
.
- process in interface Element
listener
- an ElementListener
true
if the element was processed successfully
resetCurrentColumn
public void resetCurrentColumn()
Resets the current column.
setColumnsRightToLeft
public void setColumnsRightToLeft(boolean direction)
Sets the direction of the columns.
direction
- true = right2left; false = left2right
shiftCurrentColumn
public boolean shiftCurrentColumn()
Shifts the current column.
- true if the currentcolumn has changed
type
public int type()
Gets the type of the text element.
- type in interface Element
useColumnParams
public void useColumnParams(ColumnText sourceColumn)
Copy the parameters from the specified ColumnText to use
when rendering. Parameters like setArabicOptions
must be set in this way.
write
public float write(PdfContentByte canvas,
PdfDocument document,
float documentY)
throws DocumentException
Write out the columns. After writing, use
isOverflow()
to see if all text was written.
canvas
- PdfContentByte to write withdocument
- document to write to (only used to get page limit info)documentY
- starting y position to begin writing at
- the current height (y position) after writing the columns