Package com.itextpdf.text.pdf.events
Class PdfPTableEventForwarder
- java.lang.Object
-
- com.itextpdf.text.pdf.events.PdfPTableEventForwarder
-
- All Implemented Interfaces:
PdfPTableEvent
,PdfPTableEventAfterSplit
,PdfPTableEventSplit
public class PdfPTableEventForwarder extends java.lang.Object implements PdfPTableEventAfterSplit
If you want to add more than one page event to a PdfPTable, you have to construct a PdfPTableEventForwarder, add the different events to this object and add the forwarder to the PdfWriter.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.ArrayList<PdfPTableEvent>
events
ArrayList containing all the PageEvents that have to be executed.
-
Constructor Summary
Constructors Constructor Description PdfPTableEventForwarder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addTableEvent(PdfPTableEvent event)
Add a page event to the forwarder.void
afterSplitTable(PdfPTable table, PdfPRow startRow, int startIdx)
This method is called to indicate that table has been split.void
splitTable(PdfPTable table)
This method is called to indicate that table is being split.void
tableLayout(PdfPTable table, float[][] widths, float[] heights, int headerRows, int rowStart, PdfContentByte[] canvases)
This method is called at the end of the table rendering.
-
-
-
Field Detail
-
events
protected java.util.ArrayList<PdfPTableEvent> events
ArrayList containing all the PageEvents that have to be executed.
-
-
Method Detail
-
addTableEvent
public void addTableEvent(PdfPTableEvent event)
Add a page event to the forwarder.- Parameters:
event
- an event that has to be added to the forwarder.
-
tableLayout
public void tableLayout(PdfPTable table, float[][] widths, float[] heights, int headerRows, int rowStart, PdfContentByte[] canvases)
Description copied from interface:PdfPTableEvent
This method is called at the end of the table rendering. The text or graphics are added to one of the 4PdfContentByte
contained incanvases
.
The indexes tocanvases
are:PdfPTable.BASECANVAS
- the originalPdfContentByte
. Anything placed here will be under the table.PdfPTable.BACKGROUNDCANVAS
- the layer where the background goes to.PdfPTable.LINECANVAS
- the layer where the lines go to.PdfPTable.TEXTCANVAS
- the layer where the text go to. Anything placed here will be over the table.
The
widths
andheights
have the coordinates of the cells.
The size of thewidths
array is the number of rows. Each sub-array inwidths
corresponds to the x column border positions where the first element is the x coordinate of the left table border and the last element is the x coordinate of the right table border. If colspan is not used all the sub-arrays inwidths
are the same.
For theheights
the first element is the y coordinate of the top table border and the last element is the y coordinate of the bottom table border.- Specified by:
tableLayout
in interfacePdfPTableEvent
- Parameters:
table
- thePdfPTable
in usewidths
- an array of arrays with the cells' x positions. It has the length of the number of rowsheights
- an array with the cells' y positions. It has a length of the number of rows + 1headerRows
- the number of rows defined for the header.rowStart
- the first row number after the headercanvases
- an array ofPdfContentByte
- See Also:
PdfPTableEvent.tableLayout(com.itextpdf.text.pdf.PdfPTable, float[][], float[], int, int, com.itextpdf.text.pdf.PdfContentByte[])
-
splitTable
public void splitTable(PdfPTable table)
Description copied from interface:PdfPTableEventSplit
This method is called to indicate that table is being split. It's called before thetableLayout
method and before the table is drawn.- Specified by:
splitTable
in interfacePdfPTableEventSplit
- Parameters:
table
- thePdfPTable
in use- Since:
- iText 5.0.6
- See Also:
PdfPTableEventSplit.splitTable(com.itextpdf.text.pdf.PdfPTable)
-
afterSplitTable
public void afterSplitTable(PdfPTable table, PdfPRow startRow, int startIdx)
Description copied from interface:PdfPTableEventAfterSplit
This method is called to indicate that table has been split. It's called after thetableLayout
method and after the table has been drawn on the previous page but before the rest of the table is laid out on the following page. It is meant to allow modifications of the table, e.g. by changing cells. This is useful for situations when some information has to be repeated, like putting "still" in the top cell of a column where categorizations for blocks of rows are placed, e.g. 2012 | Jan | 1000 $ | 2000 $ | Feb | 900 $ | 2100 $ -------8<----- Page break ------------- still | Mar | 1100 $ | 1900 $ 2012 | Apr | 1200 $ | 1800 $ | May | 1200 $ | 2200 $ ...
While this might be emulated by just stamping "still 2012" on the page using the currently available event callbacktableLayout
, that would fail in the case of the page break happening after the November line, because the text "still 2012" would then overlap with the new entry "2013" in the 2013 January line. This problem does not exist when modifying the first cell on the new page because that cell will the be laid out to have sufficient height so that no overlaps occur. Example:public void afterSplitTable(PdfPTable table, PdfPRow startRow, int startIdx) { PdfPCell cell = startRow.getCells()[0]; cell.addElement(new Paragraph("still " + currentYear)); }
Note that determining the value ofcurrentYear
can be done intableLayout
by noting the sizes of the tables laid out there and comparing them with the tracked row indices of the years (via table.getRows()).- Specified by:
afterSplitTable
in interfacePdfPTableEventAfterSplit
- Parameters:
table
- thePdfPTable
in usestartRow
- the firstPdfPRow
of the table body on the following pagestartIdx
- the index of that row- Since:
- iText 5.4.3
- See Also:
PdfPTableEventAfterSplit.afterSplitTable(com.itextpdf.text.pdf.PdfPTable, com.itextpdf.text.pdf.PdfPRow, int)
-
-