Class TableRenderer

java.lang.Object
com.itextpdf.layout.renderer.AbstractRenderer
com.itextpdf.layout.renderer.TableRenderer
All Implemented Interfaces:
IPropertyContainer, IRenderer

public class TableRenderer extends AbstractRenderer
This class represents the renderer object for a Table object. It will delegate its drawing operations on to the CellRenderer instances associated with the table cells.
  • Field Details

    • rows

      protected List<CellRenderer[]> rows
    • rowRange

      protected Table.RowRange rowRange
    • headerRenderer

      protected TableRenderer headerRenderer
    • footerRenderer

      protected TableRenderer footerRenderer
    • captionRenderer

      protected DivRenderer captionRenderer
    • isOriginalNonSplitRenderer

      protected boolean isOriginalNonSplitRenderer
      True for newly created renderer. For split renderers this is set to false. Used for tricky layout.
  • Constructor Details

    • TableRenderer

      public TableRenderer (Table modelElement, Table.RowRange rowRange)
      Creates a TableRenderer from a Table which will partially render the table.
      Parameters:
      modelElement - the table to be rendered by this renderer
      rowRange - the table rows to be rendered
    • TableRenderer

      public TableRenderer (Table modelElement)
      Creates a TableRenderer from a Table.
      Parameters:
      modelElement - the table to be rendered by this renderer
  • Method Details

    • addChild

      public void addChild (IRenderer renderer)
      Adds a child to the current renderer
      Specified by:
      addChild in interface IRenderer
      Overrides:
      addChild in class AbstractRenderer
      Parameters:
      renderer - a child to be added
    • applyBorderBox

      protected Rectangle applyBorderBox (Rectangle rect, Border[] borders, boolean reverse)
      Description copied from class: AbstractRenderer
      Applies the given border box (borders) on the given rectangle
      Overrides:
      applyBorderBox in class AbstractRenderer
      Parameters:
      rect - a rectangle paddings will be applied on.
      borders - the borders to be applied on the given rectangle
      reverse - indicates whether the border box will be applied inside (in case of false) or outside (in case of false) the rectangle.
      Returns:
      a border box of the renderer
    • applyPaddings

      protected Rectangle applyPaddings (Rectangle rect, UnitValue[] paddings, boolean reverse)
      Description copied from class: AbstractRenderer
      Applies given paddings on the given rectangle
      Overrides:
      applyPaddings in class AbstractRenderer
      Parameters:
      rect - a rectangle paddings will be applied on.
      paddings - the paddings to be applied on the given rectangle
      reverse - indicates whether paddings will be applied inside (in case of false) or outside (in case of false) the rectangle.
      Returns:
      a border box of the renderer
    • applyPaddings

      public Rectangle applyPaddings (Rectangle rect, boolean reverse)
      Description copied from class: AbstractRenderer
      Applies paddings of the renderer on the given rectangle
      Overrides:
      applyPaddings in class AbstractRenderer
      Parameters:
      rect - a rectangle paddings will be applied on.
      reverse - indicates whether paddings will be applied inside (in case of false) or outside (in case of false) the rectangle.
      Returns:
      a border box of the renderer
      See Also:
    • layout

      public LayoutResult layout (LayoutContext layoutContext)
      This method simulates positioning of the renderer, including all of its children, and returns the LayoutResult, representing the layout result, including occupied area, status, i.e. if there was enough place to fit the renderer subtree, etc. LayoutResult can be extended to return custom layout results for custom elements, e.g. TextRenderer uses TextLayoutResult as its result. This method can be called standalone to learn how much area the renderer subtree needs, or can be called before IRenderer.draw(DrawContext), to prepare the renderer to be flushed to the output stream.
      Parameters:
      layoutContext - the description of layout area and any other additional information
      Returns:
      result of the layout process
    • draw

      public void draw (DrawContext drawContext)
      Flushes the renderer subtree contents, i.e. draws itself on canvas, adds necessary objects to the PdfDocument etc.
      Specified by:
      draw in interface IRenderer
      Overrides:
      draw in class AbstractRenderer
      Parameters:
      drawContext - contains the PdfDocument to which the renderer subtree if flushed, the PdfCanvas on which the renderer subtree is drawn and other additional parameters needed to perform drawing
    • drawChildren

      public void drawChildren (DrawContext drawContext)
      Performs the drawing operation for all children of this renderer.
      Overrides:
      drawChildren in class AbstractRenderer
      Parameters:
      drawContext - the context (canvas, document, etc) of this drawing operation.
    • drawBackgrounds

      protected void drawBackgrounds (DrawContext drawContext)
    • drawCaption

      protected void drawCaption (DrawContext drawContext)
    • drawBackground

      public void drawBackground (DrawContext drawContext)
      Description copied from class: AbstractRenderer
      Draws a background layer if it is defined by a key Property.BACKGROUND in either the layout element or this IRenderer itself.
      Overrides:
      drawBackground in class AbstractRenderer
      Parameters:
      drawContext - the context (canvas, document, etc) of this drawing operation.
    • getNextRenderer

      public IRenderer getNextRenderer()
      Gets a new instance of this class to be used as a next renderer, after this renderer is used, if layout(LayoutContext) is called more than once.

      If a renderer overflows to the next area, iText uses this method to create a renderer for the overflow part. So if one wants to extend TableRenderer, one should override this method: otherwise the default method will be used and thus the default rather than the custom renderer will be created.

      Returns:
      new renderer instance
    • move

      public void move (float dxRight, float dyUp)
      Moves the renderer subtree by the specified offset. This method affects occupied area of the renderer.
      Specified by:
      move in interface IRenderer
      Overrides:
      move in class AbstractRenderer
      Parameters:
      dxRight - the x-axis offset in points. Positive value will move the renderer subtree to the right.
      dyUp - the y-axis offset in points. Positive value will move the renderer subtree to the top.
    • split

      protected TableRenderer[] split (int row)
    • split

      protected TableRenderer[] split (int row, boolean hasContent)
    • split

      protected TableRenderer[] split (int row, boolean hasContent, boolean cellWithBigRowspanAdded)
    • createSplitRenderer

      protected TableRenderer createSplitRenderer (Table.RowRange rowRange)
    • createOverflowRenderer

      protected TableRenderer createOverflowRenderer (Table.RowRange rowRange)
    • retrieveWidth

      protected Float retrieveWidth (float parentBoxWidth)
      Description copied from class: AbstractRenderer
      Retrieves element's fixed content box width, if it's set. Takes into account Property.BOX_SIZING, Property.MIN_WIDTH, and Property.MAX_WIDTH properties.
      Overrides:
      retrieveWidth in class AbstractRenderer
      Parameters:
      parentBoxWidth - width of the parent element content box. If element has relative width, it will be calculated relatively to this parameter.
      Returns:
      element's fixed content box width or null if it's not set.
      See Also:
    • getMinMaxWidth

      public MinMaxWidth getMinMaxWidth()
      Description copied from class: AbstractRenderer
      Calculates min and max width values for current renderer.
      Overrides:
      getMinMaxWidth in class AbstractRenderer
      Returns:
      instance of MinMaxWidth
    • allowLastYLineRecursiveExtraction

      protected boolean allowLastYLineRecursiveExtraction()
      Overrides:
      allowLastYLineRecursiveExtraction in class AbstractRenderer
    • drawBorder

      public void drawBorder (DrawContext drawContext)
      Description copied from class: AbstractRenderer
      Performs the drawing operation for the border of this renderer, if defined by any of the Property.BORDER values in either the layout element or this IRenderer itself.
      Overrides:
      drawBorder in class AbstractRenderer
      Parameters:
      drawContext - the context (canvas, document, etc) of this drawing operation.
    • drawBorders

      protected void drawBorders (DrawContext drawContext)
    • extendLastRow

      protected void extendLastRow (CellRenderer[] lastRow, Rectangle freeBox)