PhraseWithColorRedAndNormalFontPDF.java Source code

Java tutorial

Introduction

Here is the source code for PhraseWithColorRedAndNormalFontPDF.java

Source

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