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("ttc.pdf"));

        document.open();
        BaseFont bf;
        Font font;
        bf = BaseFont.createFont("c:/windows/fonts/msgothic.ttc,0", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
        font = new Font(bf, 12);
        System.err.println(bf.getClass().getName());
        document.add(new Paragraph("abcde", font));
        document.add(new Paragraph("\u7f85\u751f\u9580", font));
        String[] names = BaseFont.enumerateTTCNames("c:/windows/fonts/msgothic.ttc");
        for (int i = 0; i < names.length; i++) {
            document.add(new Paragraph("font " + i + ": " + names[i], font));
        }
        document.close();
    }
}