Search in sources :

Example 1 with RtfTOCEntry

use of com.lowagie.text.rtf.field.RtfTOCEntry in project itext2 by albfernandez.

the class RtfTOCandCellbordersTest method main.

/**
 * 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();
}
Also used : Table(com.lowagie.text.Table) RtfBorderGroup(com.lowagie.text.rtf.table.RtfBorderGroup) Color(java.awt.Color) Chapter(com.lowagie.text.Chapter) RtfCell(com.lowagie.text.rtf.table.RtfCell) Document(com.lowagie.text.Document) RtfTableOfContents(com.lowagie.text.rtf.field.RtfTableOfContents) RtfTOCEntry(com.lowagie.text.rtf.field.RtfTOCEntry) RtfWriter2(com.lowagie.text.rtf.RtfWriter2) Paragraph(com.lowagie.text.Paragraph) Test(org.junit.Test)

Aggregations

Chapter (com.lowagie.text.Chapter)1 Document (com.lowagie.text.Document)1 Paragraph (com.lowagie.text.Paragraph)1 Table (com.lowagie.text.Table)1 RtfWriter2 (com.lowagie.text.rtf.RtfWriter2)1 RtfTOCEntry (com.lowagie.text.rtf.field.RtfTOCEntry)1 RtfTableOfContents (com.lowagie.text.rtf.field.RtfTableOfContents)1 RtfBorderGroup (com.lowagie.text.rtf.table.RtfBorderGroup)1 RtfCell (com.lowagie.text.rtf.table.RtfCell)1 Color (java.awt.Color)1 Test (org.junit.Test)1