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();
}
Aggregations