1   package org.intix.itext.test;
2   
3   import java.awt.*;
4   import java.io.*;
5   
6   import com.lowagie.text.*;
7   import com.lowagie.text.pdf.*;
8   
9   class PhraseDemo {
10  	public static void main(String[] args) throws Exception {
11  		Document doc = new Document();
12  		PdfWriter.getInstance(doc, new FileOutputStream("./test/phrasedemo.pdf"));
13  		doc.open();
14  
15  		// Construct a phrase.
16  
17  		Phrase p = new Phrase("Here are the rules about traffic lights. ");
18  
19  		// Add a chunk to phrase containing word Red -- bolded and colored red.
20  
21  		Chunk ck = new Chunk("Red");
22  		ck.setTextRenderMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE, 1,
23  				Color.red);
24  		p.add(ck);
25  
26  		// Strings can also be added to Phrases.
27  
28  		p.add(" means stop. ");
29  
30  		// Add a chunk to phrase containing word Green -- bolded and colored
31  		// green.
32  
33  		ck = new Chunk("Green");
34  		ck.setTextRenderMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE, 1,
35  				Color.green);
36  		p.add(ck);
37  
38  		// Even Phrases can be added to Phrases.
39  
40  		p.add(new Phrase(" means go. "));
41  
42  		// Add a chunk to phrase containing word Yellow -- bolded and colored
43  		// yellow.
44  
45  		ck = new Chunk("Yellow");
46  		ck.setTextRenderMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE, 1,
47  				Color.yellow);
48  		p.add(ck);
49  
50  		p.add(" means proceed with caution.");
51  
52  		// Add phrase to document.
53  
54  		doc.add(p);
55  
56  		doc.close();
57  	}
58  }