Tutorial: iText by Example

Extended table cell support

Extended table cell support:
Similarly to the situation with headers and footers it is not possible to create advanced cell borders using page events in the RTF package.

To overcome this the RtfCell class exists, which makes it possible to specify advanced borders. To do this create a RtfBorderGroup and specify the style for that RtfBorderGroup, then apply it to the RtfCell.
// Create a simple RtfCell with a dotted border.
RtfCell cellDotted = new RtfCell("Dotted border");
cellDotted.setBorders(new RtfBorderGroup(Rectangle.BOX,
        RtfBorder.BORDER_DOTTED, 1, new Color(0, 0, 0)));
		  
You can also create RtfCells that have a border on only one side
// Create a simple RtfCell that only has a border on the bottom side.
RtfCell bottomBorder = new RtfCell("Bottom border");
bottomBorder.setBorders(new RtfBorderGroup(Rectangle.BOTTOM,
        RtfBorder.BORDER_SINGLE, 2, new Color(255, 0, 0)));
		  
or that have different borders on different sides of the RtfCell.
// Create a simple RtfCell that has different borders
// on the left and bottom sides.
RtfCell mixedBorder = new RtfCell("Mixed border");
RtfBorderGroup mixedBorders = new RtfBorderGroup();
mixedBorders.addBorder(Rectangle.RIGHT,
        RtfBorder.BORDER_DOUBLE_WAVY, 2, Color.GREEN);
mixedBorders.addBorder(Rectangle.BOTTOM,
        RtfBorder.BORDER_DOT_DASH, 1, Color.BLUE);
mixedBorder.setBorders(mixedBorders);
          
Finally if you want a RtfCell without any borders simply set an empty RtfBorderGroup.
// Create a simple RtfCell with no border.
RtfCell cellNoBorder = new RtfCell("No border");
cellNoBorder.setBorders(new RtfBorderGroup());
          
For a full list of the border styles that are available, please check the javadoc for the RtfBorder class.
Example: java com.lowagie.examples.rtf.extensions.table.ExtendedTableCell
Generates an RTF document with a Table with specific borders per cell: see ExtendedTableCell.rtf
Extra jars needed in your CLASSPATH: itext-rtf.jar
Go to top of the page

iText, the #1 Java-PDF library




Amazon books:
amazon.co.uk-link