Phrase with Color red and Normal Font : Phrase « PDF RTF « Java






Phrase with Color red and Normal Font

Phrase with Color red and Normal Font
import java.awt.Color;
import java.io.FileOutputStream;
import java.io.IOException;

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

public class PhraseWithColorRedAndNormalFontPDF {
  public static void main(String[] args) {
    Document document = new Document();
    try {
      PdfWriter.getInstance(document, new FileOutputStream("PhraseWithColorRedAndNormalFontPDF.pdf"));

      document.open();

      Phrase phrase = new Phrase("(3) this is a phrase with a red, normal font Courier, size 20.\n",
                                 FontFactory.getFont(FontFactory.COURIER, 20, Font.NORMAL,
                                 new Color(255, 0, 0)));
      document.add(phrase);
    } catch (DocumentException de) {
      System.err.println(de.getMessage());
    } catch (IOException ioe) {
      System.err.println(ioe.getMessage());
    }

    document.close();
  }
}
           
       








itext.zip( 1,748 k)

Related examples in the same category

1.Adding Chunk to a PhraseAdding Chunk to a Phrase
2.Phrase with Leading LinePhrase with Leading Line
3.Phrase with Several Chunks and Different Fonts