Search in sources :

Example 1 with RtfTabGroup

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

the class TabGroupsTest method main.

/**
 * Using the RtfTabGroup to simplify adding a set of tab stops.
 */
@Test
public void main() throws Exception {
    Document document = new Document();
    RtfWriter2.getInstance(document, PdfTestBase.getOutputStream("TabGroups.rtf"));
    document.open();
    // Construct the RtfTabGroup object
    RtfTabGroup tabGroup = new RtfTabGroup();
    // Add RtfTab tab stops at the desired positions
    tabGroup.add(new RtfTab(400, RtfTab.TAB_RIGHT_ALIGN));
    tabGroup.add(new RtfTab(500, RtfTab.TAB_DECIMAL_ALIGN));
    // Create a Paragraph object
    Paragraph par = new Paragraph();
    // Add the tab group to the paragraph
    par.add(tabGroup);
    // Specify the tab positions using "\t"
    par.add("Description\tDate\tAmount");
    document.add(par);
    DecimalFormat nf = new DecimalFormat("#.00");
    double sum = 0;
    for (int i = 0; i < 10; i++) {
        double value = Math.random() * 100;
        sum = sum + value;
        par = new Paragraph();
        // The RtfTabGroup can be reused for further paragraphs
        par.add(tabGroup);
        par.add("Item " + (i + 1) + "\t" + (12 + i) + ".03.2007\t" + nf.format(value));
        document.add(par);
    }
    par = new Paragraph("", new Font(Font.TIMES_ROMAN, 12, Font.BOLD));
    par.add(tabGroup);
    // If a tab in the RtfTabGroup is not needed, just add an empty tab stop in the text
    par.add("Total\t\t" + nf.format(sum));
    document.add(par);
    document.close();
}
Also used : DecimalFormat(java.text.DecimalFormat) RtfTabGroup(com.lowagie.text.rtf.text.RtfTabGroup) Document(com.lowagie.text.Document) RtfTab(com.lowagie.text.rtf.text.RtfTab) Font(com.lowagie.text.Font) Paragraph(com.lowagie.text.Paragraph) Test(org.junit.Test)

Aggregations

Document (com.lowagie.text.Document)1 Font (com.lowagie.text.Font)1 Paragraph (com.lowagie.text.Paragraph)1 RtfTab (com.lowagie.text.rtf.text.RtfTab)1 RtfTabGroup (com.lowagie.text.rtf.text.RtfTabGroup)1 DecimalFormat (java.text.DecimalFormat)1 Test (org.junit.Test)1