/** * Creates an RTF document with a TOC and Table with special Cellborders. * * */ @Test public void main() throws Exception { Document document = new Document(); RtfWriter2 writer2 = RtfWriter2.getInstance(document, PdfTestBase.getOutputStream("toc.rtf")); writer2.setAutogenerateTOCEntries(true); document.open(); Paragraph para = new Paragraph(); para.add(new RtfTableOfContents("RIGHT CLICK AND HERE AND SELECT \"UPDATE FIELD\" TO UPDATE.")); document.add(para); Paragraph par = new Paragraph("This is some sample content."); Chapter chap1 = new Chapter("Chapter 1", 1); chap1.add(par); Chapter chap2 = new Chapter("Chapter 2", 2); chap2.add(par); document.add(chap1); document.add(chap2); for (int i = 0; i < 300; i++) { if (i == 158) { document.add(new RtfTOCEntry("This is line 158.")); } document.add(new Paragraph("Line " + i)); } document.add(new RtfTOCEntry("Cell border demonstration")); Table table = new Table(3); RtfCell cellDotted = new RtfCell("Dotted border"); cellDotted.setBorders(new RtfBorderGroup(Rectangle.BOX, RtfBorder.BORDER_DOTTED, 1, new Color(0, 0, 0))); RtfCell cellEmbossed = new RtfCell("Embossed border"); cellEmbossed.setBorders(new RtfBorderGroup(Rectangle.BOX, RtfBorder.BORDER_EMBOSS, 1, new Color(0, 0, 0))); RtfCell cellNoBorder = new RtfCell("No border"); cellNoBorder.setBorders(new RtfBorderGroup()); table.addCell(cellDotted); table.addCell(cellEmbossed); table.addCell(cellNoBorder); document.add(table); document.close(); }
/** * Extended borders for Table Cells. * * */ @Test public void main() throws Exception { Document document = new Document(); RtfWriter2.getInstance(document, PdfTestBase.getOutputStream("ExtendedTableCell.rtf")); document.open(); Table table = new Table(3); // 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))); // Create a simple RtfCell with an embossed border. RtfCell cellEmbossed = new RtfCell("Embossed border"); cellEmbossed.setBorders(new RtfBorderGroup(Rectangle.BOX, RtfBorder.BORDER_EMBOSS, 1, new Color(0, 0, 0))); // Create a simple RtfCell with no border. RtfCell cellNoBorder = new RtfCell("No border"); cellNoBorder.setBorders(new RtfBorderGroup()); cellNoBorder.setRowspan(2); // 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))); // 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); // Add the cells to the table table.addCell(cellDotted); table.addCell(cellEmbossed); table.addCell(cellNoBorder); table.addCell(bottomBorder); table.addCell(mixedBorder); document.add(table); document.close(); }