MainClass.java Source code

Java tutorial

Introduction

Here is the source code for MainClass.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.pdf.BaseFont;
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("ttf.pdf"));
        document.open();
        BaseFont bf = BaseFont.createFont("c:/windows/fonts/ARBLI___.ttf", BaseFont.CP1252, BaseFont.EMBEDDED);
        Font font = new Font(bf, 12);
        System.err.println(bf.getClass().getName());
        document.add(new Paragraph("This is font arial black italic (embedded)", font));
        bf = BaseFont.createFont("c:/windows/fonts/ARBLI___.ttf", BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        font = new Font(bf, 12);
        document.add(new Paragraph("This is font arial black italic (not embedded)", font));
        System.out.println("PostScript name:" + bf.getPostscriptFontName());

        String[] encoding = bf.getCodePagesSupported();
        for (int i = 0; i < encoding.length; i++) {
            System.out.println("encoding[" + i + "] = " + encoding[i]);
        }
        document.newPage();
        String[][] name = bf.getFullFontName();
        for (int i = 0; i < name.length; i++) {
            System.out.println(name[i][3] + " (" + name[i][0] + "; " + name[i][1] + "; " + name[i][2] + ")");
        }
        document.close();
    }
}