1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| public static void main(String[] args) {
System.out.println("This example generate a RTF file name Sample.rtf");
// Create Document object
Document myDoc = new Document();
try {
// Create writer to listen document object
// and directs RTF Stream to the file Sample.rtf
RtfWriter2.getInstance(myDoc, new FileOutputStream("Sample.rtf"));
// open the document object
myDoc.open();
// Create a paragraph
Paragraph p = new Paragraph();
Font fontRed = FontFactory.getFont(FontFactory.TIMES_ITALIC, 14, Font.BOLDITALIC, new Color(0,153,102));
p.setFont(fontRed);
//p.setFont(null)
p.add("Bonjour");
Phrase phrase = new Phrase("nouvelle phrase colorée");
phrase.setFont(new Font(14));
// Add the paragraph to document object
myDoc.add(p);
myDoc.add(phrase);
}
catch(Exception e) {
System.out.println(e);
}
//close the document
myDoc.close();
} |
Partager