FontSelectionPDF.java Source code

Java tutorial

Introduction

Here is the source code for FontSelectionPDF.java

Source

import java.io.FileOutputStream;

import com.lowagie.text.Document;
import com.lowagie.text.Font;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.FontSelector;
import com.lowagie.text.pdf.PdfWriter;

public class FontSelectionPDF {
    public static void main(String[] args) throws Exception {
        Document document = new Document();
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("FontSelectionPDF.pdf"));
        document.open();
        String text = "Text Text Text Text Text Text Text, Text Text Text Text Text Text Text Text, Text Text Text Text Text Text Text Text Text Text Text Text Text ";
        FontSelector sel = new FontSelector();
        sel.addFont(new Font(Font.TIMES_ROMAN, 12));
        sel.addFont(new Font(Font.ZAPFDINGBATS, 12));
        sel.addFont(new Font(Font.SYMBOL, 12));
        Phrase ph = sel.process(text);
        document.add(new Paragraph(ph));
        document.close();
    }
}