UnicodeExamplePDF.java Source code

Java tutorial

Introduction

Here is the source code for UnicodeExamplePDF.java

Source

import java.io.FileOutputStream;
import java.io.IOException;

import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Font;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfWriter;

public class UnicodeExamplePDF {
    public static void main(String[] args) {
        Document document = new Document();

        try {
            PdfWriter.getInstance(document, new FileOutputStream("UnicodeExamplePDF.pdf"));
            document.open();

            BaseFont bfComic = BaseFont.createFont("c:\\windows\\fonts\\arial.ttf", BaseFont.IDENTITY_H,
                    BaseFont.EMBEDDED);
            document.add(new Paragraph("Unicode: \u0418", new Font(bfComic, 12)));
        } catch (Exception e) {
            System.err.println(e.getMessage());
        }
        document.close();
    }
}