Create Phrase from a chunk : Phrase « PDF « Java Tutorial






import java.awt.Color;
import java.io.FileOutputStream;

import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.Font;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.PdfWriter;

public class MainClass {

  public static void main(String[] args) throws Exception {
    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    document.open();
    Font font = new Font(Font.COURIER, 10, Font.BOLD);
    font.setColor(new Color(0xFF, 0xFF, 0xFF));
    Chunk fox = new Chunk("this is a", font);
    fox.setBackground(new Color(0xa5, 0x2a, 0x2a));
    Phrase p = new Phrase(fox);
    p.add(" test");
    Chunk dog = new Chunk(" another test", new Font(Font.TIMES_ROMAN, 14, Font.ITALIC));
    dog.setBackground(new Color(0xFF, 0x00, 0x00), 10, -30, 20, -10);
    p.add(dog);
    document.add(p);
    document.close();
  }
}








29.19.Phrase
29.19.1.Create Phrase from a chunk