import java.lang.*;
import java.io.*;
import java.util.*;
import java.text.*;

import com.pdfjet.*;


/**
 *  Example_04.java
 *
 *  The PDF generated by this example program will only work with Adobe Reader 8
 *  or Foxit Reader v2.0 or higher versions. It also requires the Asian Font Packs
 *  from Adobe or Foxit Software respectively.
 */
public class Example_04 {

    public Example_04() throws Exception {

        PDF pdf = new PDF();
        Font f1 = new Font(
                pdf,
                "AdobeMingStd-Light",       // Chinese (Traditional) font
                CodePage.UNICODE);
        Font f2 = new Font(
                pdf,
                "AdobeSongStd-Light",       // Chinese (Simplified) font
                CodePage.UNICODE);
        Font f3 = new Font(
                pdf,
                "KozMinProVI-Regular",      // Japanese font
                CodePage.UNICODE);
        Font f4 = new Font(
                pdf,
                "AdobeMyungjoStd-Medium",   // Korean font
                CodePage.UNICODE);

        Page page = new Page(pdf, Letter.PORTRAIT);

        f1.setSize(14);
        f2.setSize(14);
        f3.setSize(14);
        f4.setSize(14);

        double x_pos = 100.0;
        double y_pos = 20.0;
        BufferedReader reader = new BufferedReader(
                new InputStreamReader(
                        new FileInputStream(
                                "data/happy-new-year.txt"),
                                "UTF-8"));
        TextLine text = new TextLine(f1);
        String line = null;
        while ((line = reader.readLine()) != null) {
            if (line.indexOf("Simplified") != -1) {
                text.setFont(f2);
            } else if (line.indexOf("Japanese") != -1) {
                text.setFont(f3);
            } else if (line.indexOf("Korean") != -1) {
                text.setFont(f4);
            }
            text.setText(line);
            text.setPosition(x_pos, y_pos += 24);
            text.drawOn(page);
        }
        reader.close();

        pdf.wrap();
        pdf.save("Example_04.pdf");
    }


    public static void main(String[] args) {
        try {
            new Example_04();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}   // End of Example_04.java
