Search in sources :

Example 6 with RtfWriter2

use of com.lowagie.text.rtf.RtfWriter2 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)

Example 7 with RtfWriter2

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

the class DocumentSettingsTest method main.

/**
 * Document settings example.
 */
@Test
public void main() throws Exception {
    Document document = new Document();
    // Keep a reference to the RtfWriter2 instance.
    RtfWriter2 writer2 = RtfWriter2.getInstance(document, PdfTestBase.getOutputStream("DocumentSettings.rtf"));
    // Specify that the document caching is to be done on disk.
    writer2.getDocumentSettings().setDataCacheStyle(RtfDataCache.CACHE_DISK);
    // Specify that all \n are translated into soft linebreaks.
    writer2.getDocumentSettings().setAlwaysGenerateSoftLinebreaks(true);
    document.open();
    document.add(new Paragraph("This example has been cached on disk\nand all " + "\\n have been translated into soft linebreaks."));
    document.close();
}
Also used : Document(com.lowagie.text.Document) RtfWriter2(com.lowagie.text.rtf.RtfWriter2) Paragraph(com.lowagie.text.Paragraph) Test(org.junit.Test)

Aggregations

Paragraph (com.lowagie.text.Paragraph)7 RtfWriter2 (com.lowagie.text.rtf.RtfWriter2)7 Document (com.lowagie.text.Document)6 Test (org.junit.Test)6 RtfTableOfContents (com.lowagie.text.rtf.field.RtfTableOfContents)3 Anchor (com.lowagie.text.Anchor)2 Chapter (com.lowagie.text.Chapter)2 HeaderFooter (com.lowagie.text.HeaderFooter)2 Phrase (com.lowagie.text.Phrase)2 Table (com.lowagie.text.Table)2 RtfHeaderFooter (com.lowagie.text.rtf.headerfooter.RtfHeaderFooter)2 RtfParagraphStyle (com.lowagie.text.rtf.style.RtfParagraphStyle)2 RtfBorderGroup (com.lowagie.text.rtf.table.RtfBorderGroup)2 RtfCell (com.lowagie.text.rtf.table.RtfCell)2 Color (java.awt.Color)2 Annotation (com.lowagie.text.Annotation)1 Cell (com.lowagie.text.Cell)1 Chunk (com.lowagie.text.Chunk)1 Font (com.lowagie.text.Font)1 Image (com.lowagie.text.Image)1