Class Table

All Implemented Interfaces:
CssAppliersAware, TagProcessor

public class Table extends AbstractTagProcessor
  • Field Details

  • Constructor Details

    • Table

      public Table()
      Default constructor.
  • Method Details

    • end

      public List<Element> end(WorkerContext ctx, Tag tag, List<Element> currentContent)
      Description copied from class: AbstractTagProcessor
      Classes extending AbstractTagProcessor should override this method for actions that should be done in TagProcessor.endElement(WorkerContext, Tag, List). The AbstractTagProcessor.endElement(WorkerContext, Tag, List) calls this method after or before doing certain stuff, (see it's description).
      Overrides:
      end in class AbstractTagProcessor
      Parameters:
      ctx - the WorkerContext
      tag - the tag
      currentContent - the content created from e.g. inner tags, inner content and not yet added to document.
      Returns:
      a List containing iText Element objects
    • intPdfPTable

      protected PdfPTable intPdfPTable(int numberOfColumn)
    • calculateTargetWidth

      private float calculateTargetWidth(Tag tag, float[] columnWidths, float outerWidth, WorkerContext ctx) throws NoCustomContextException
      Calculates the target width. First checks:
      1. if the attribute or style "width" is found in the given tag and it is not wider than pageWidth - outerWidth, then the targetWidth = width value
      2. if the columnWidths array in total is not wider than pageWidth - outerWidth, then the targetWidth = the total of the columnWidths array
      3. if table's parent is a root tag or table has no parent, then the targetWidth = width of the page - outerWidth getTableOuterWidth(Tag, float, WorkerContext).
      If none of the above is true, the width of the table is set to its default with the columnWidths array.
      Parameters:
      tag - containing attributes and css.
      columnWidths - float[] containing the widest lines of text found in the columns.
      outerWidth - width needed for margins and borders.
      ctx -
      Returns:
      float the target width of a table.
      Throws:
      NoCustomContextException
    • widenLastCell

      private void widenLastCell(List<TableRowElement> tableRows, float horBorderSpacing)
      Adds horizontal border spacing to the right padding of the last cell of each row.
      Parameters:
      tableRows - List of TableRowElement objects of the table.
      horBorderSpacing - float containing the horizontal border spacing of the table.
    • setStyleValues

      public static TableStyleValues setStyleValues(Tag tag)
      Set the table style values in a TableStyleValues object based on attributes and css of the given tag.
      Parameters:
      tag - containing attributes and css.
      Returns:
      a TableStyleValues object containing the table's style values.
    • setBorderAttributeForCell

      public static TableStyleValues setBorderAttributeForCell(Tag tag)
    • getBorderOrCellSpacing

      public static float getBorderOrCellSpacing(boolean getHor, Map<String,String> css, Map<String,String> attributes)
      Extracts and parses the style border-spacing or the attribute cellspacing of a table tag, if present. Favors the style border-spacing over the attribute cellspacing.
      If style="border-collapse:collapse" is found in the css, the spacing is always 0f.
      If no spacing is set, the default of 1.5pt is returned.
      Parameters:
      getHor - true for horizontal spacing, false for vertical spacing.
      css - of the table tag.
      attributes - of the table tag.
      Returns:
      horizontal or vertical spacing between two cells or a cell and the border of the table.
    • setCellWidthAndWidestWord

      private float[] setCellWidthAndWidestWord(HtmlCell cell)
      Sets the default cell width and widest word of a cell. These 2 widths are used as the starting point when determining the width of the table in
      Parameters:
      cell - HtmlCell of which the widths are needed.
      Returns:
      float array containing the default cell width and the widest word.
      • float[0] = cell width.
      • float[1] = widest word.
    • calculateDivWidestElementWidth

      private float calculateDivWidestElementWidth(ArrayList<Element> divContent)
      An attempt to calculate a valid div width in case it is not fixed. It is used as alternative to div.getActualWidth, which doesn't work here in case of not fixed div's width (it returns 0). This method is probably has to be improved in future. The main idea of this method is to return the widest element's width, so the created cell will be able to contain it.
    • getTableWidth

      private float getTableWidth(float[] widths, float outerWidth) throws NoCustomContextException
      Calculates the total width based on the given widths array and the given outer width.
      Parameters:
      widths - array of floats containing column width values.
      outerWidth - equals the required space outside of the table for margins and borders.
      Returns:
      a table's width.
      Throws:
      NoCustomContextException
    • getTableOuterWidth

      private float getTableOuterWidth(Tag tag, float horBorderSpacing, WorkerContext ctx) throws NoCustomContextException
      Adds horizontal values of a table and its parent if present. Following values are added up:
      • left and right margins of the table.
      • left and right border widths of the table.
      • left and right margins of the parent of the table is present.
      • one horizontal border spacing.
      Parameters:
      tag -
      horBorderSpacing -
      ctx -
      Returns:
      float containing the needed space for margins of table and parent(s) and the borders of the table.
      Throws:
      NoCustomContextException
    • getCellStartWidth

      private float getCellStartWidth(HtmlCell cell)
      Calculates the start width of a cell. Following values are added up:
      • padding left, this includes left border width and a horizontal border spacing.
      • padding right, this includes right border width.
      • the (colspan - 1) * horizontal border spacing.
      Parameters:
      cell - HtmlCell of which the start width is needed.
      Returns:
      float containing the start width.
    • setVerticalMargin

      private void setVerticalMargin(PdfPTable table, Tag t, TableStyleValues values, WorkerContext ctx) throws NoCustomContextException
      Sets the top and bottom margin of the given table.
      Parameters:
      table - PdfPTable on which the margins need to be set.
      t - Tag containing the margin styles and font size if needed.
      values - TableStyleValues containing border widths and border spacing values.
      ctx -
      Throws:
      NoCustomContextException
    • isStackOwner

      public boolean isStackOwner()
      Description copied from class: AbstractTagProcessor
      Defaults to false.
      Specified by:
      isStackOwner in interface TagProcessor
      Overrides:
      isStackOwner in class AbstractTagProcessor
      Returns:
      true if the tag implementation must keep it's own currentContent stack.
      See Also: