Using Font Factory to Get all Registered Families
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.TreeSet;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.FontFactory;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfWriter;
public class UsingFontFactoryToGetAllRegisterFamilies {
public static void main(String[] args) {
Document document = new Document();
try {
PdfWriter.getInstance(document, new FileOutputStream("UsingFontFactoryToGetAllRegisterFamilies.pdf"));
document.open();
Paragraph p = new Paragraph("Font Families", FontFactory.getFont(FontFactory.HELVETICA, 16f));
document.add(p);
FontFactory.registerDirectories();
TreeSet families = new TreeSet(FontFactory.getRegisteredFamilies());
for (Iterator i = families.iterator(); i.hasNext();) {
String name = (String) i.next();
p = new Paragraph(name, FontFactory.getFont(name, BaseFont.WINANSI, BaseFont.EMBEDDED));
document.add(p);
}
} catch (Exception e) {
System.err.println(e.getMessage());
}
document.close();
}
}
itext.zip( 1,748 k)Related examples in the same category