Package com.itextpdf.tool.xml.html.table
Class Table
- java.lang.Object
-
- com.itextpdf.tool.xml.html.AbstractTagProcessor
-
- com.itextpdf.tool.xml.html.table.Table
-
- All Implemented Interfaces:
CssAppliersAware,TagProcessor
public class Table extends AbstractTagProcessor
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classTable.NormalRowComparatorReorganizes table rows based on the designated normalTableRowElement.Placein a table.private classTable.RepeatedRowComparatorReorganizes table rows based on the designated repeatedTableRowElement.Placein a table.
-
Field Summary
Fields Modifier and Type Field Description static floatDEFAULT_CELL_BORDER_WIDTHprivate static FontSizeTranslatorfstprivate static LoggerLOGprivate static CssUtilsutils
-
Constructor Summary
Constructors Constructor Description Table()Default constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private floatcalculateDivWidestElementWidth(java.util.ArrayList<Element> divContent)An attempt to calculate a valid div width in case it is not fixed.private floatcalculateTargetWidth(Tag tag, float[] columnWidths, float outerWidth, WorkerContext ctx)Calculates the target width.java.util.List<Element>end(WorkerContext ctx, Tag tag, java.util.List<Element> currentContent)Classes extending AbstractTagProcessor should override this method for actions that should be done inTagProcessor.endElement(WorkerContext, Tag, List).static floatgetBorderOrCellSpacing(boolean getHor, java.util.Map<java.lang.String,java.lang.String> css, java.util.Map<java.lang.String,java.lang.String> attributes)Extracts and parses the style border-spacing or the attribute cellspacing of a table tag, if present.private floatgetCellStartWidth(HtmlCell cell)Calculates the start width of a cell.private floatgetTableOuterWidth(Tag tag, float horBorderSpacing, WorkerContext ctx)Adds horizontal values of a table and its parent if present.private floatgetTableWidth(float[] widths, float outerWidth)Calculates the total width based on the given widths array and the given outer width.protected PdfPTableintPdfPTable(int numberOfColumn)booleanisStackOwner()Defaults to false.static TableStyleValuessetBorderAttributeForCell(Tag tag)private float[]setCellWidthAndWidestWord(HtmlCell cell)Sets the default cell width and widest word of a cell.static TableStyleValuessetStyleValues(Tag tag)Set the table style values in aTableStyleValuesobject based on attributes and css of the given tag.private voidsetVerticalMargin(PdfPTable table, Tag t, TableStyleValues values, WorkerContext ctx)Sets the top and bottom margin of the given table.private voidwidenLastCell(java.util.List<TableRowElement> tableRows, float horBorderSpacing)Adds horizontal border spacing to the right padding of the last cell of each row.-
Methods inherited from class com.itextpdf.tool.xml.html.AbstractTagProcessor
content, createParagraph, currentContentToParagraph, currentContentToParagraph, doRtlIndentCorrections, endElement, getCssAppliers, getCSSResolver, getHtmlPipelineContext, getRunDirection, invertTextAlignForParagraph, invertTextAlignForParagraph, setCssAppliers, start, startElement, textContent, updateParagraphFontIfNeeded
-
-
-
-
Field Detail
-
DEFAULT_CELL_BORDER_WIDTH
public static final float DEFAULT_CELL_BORDER_WIDTH
- See Also:
- Constant Field Values
-
LOG
private static final Logger LOG
-
utils
private static final CssUtils utils
-
fst
private static final FontSizeTranslator fst
-
-
Method Detail
-
end
public java.util.List<Element> end(WorkerContext ctx, Tag tag, java.util.List<Element> currentContent)
Description copied from class:AbstractTagProcessorClasses extending AbstractTagProcessor should override this method for actions that should be done inTagProcessor.endElement(WorkerContext, Tag, List). TheAbstractTagProcessor.endElement(WorkerContext, Tag, List)calls this method after or before doing certain stuff, (see it's description).- Overrides:
endin classAbstractTagProcessor- Parameters:
ctx- the WorkerContexttag- the tagcurrentContent- 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:- 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
- if the columnWidths array in total is not wider than pageWidth - outerWidth, then the targetWidth = the total of the columnWidths array
- 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).
- 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(java.util.List<TableRowElement> tableRows, float horBorderSpacing)
Adds horizontal border spacing to the right padding of the last cell of each row.- Parameters:
tableRows- List ofTableRowElementobjects 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 aTableStyleValuesobject based on attributes and css of the given tag.- Parameters:
tag- containing attributes and css.- Returns:
- a
TableStyleValuesobject containing the table's style values.
-
setBorderAttributeForCell
public static TableStyleValues setBorderAttributeForCell(Tag tag)
-
getBorderOrCellSpacing
public static float getBorderOrCellSpacing(boolean getHor, java.util.Map<java.lang.String,java.lang.String> css, java.util.Map<java.lang.String,java.lang.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.- cell width =
getCellStartWidth(HtmlCell)+ the width of the widest line of text. - widest word =
getCellStartWidth(HtmlCell)+ the widest word of the cell.
- 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.
- cell width =
-
calculateDivWidestElementWidth
private float calculateDivWidestElementWidth(java.util.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 NoCustomContextExceptionCalculates 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-TableStyleValuescontaining border widths and border spacing values.ctx-- Throws:
NoCustomContextException
-
isStackOwner
public boolean isStackOwner()
Description copied from class:AbstractTagProcessorDefaults to false.- Specified by:
isStackOwnerin interfaceTagProcessor- Overrides:
isStackOwnerin classAbstractTagProcessor- Returns:
- true if the tag implementation must keep it's own currentContent stack.
- See Also:
TagProcessor.isStackOwner()
-
-