Example_02

Drawing Japanese, Korean, Simplified Chinese and Traditional Chinese text with embedded IBM Plex Sans fonts.

Example_02.pdf — the PDF this example creates.

/*
 * Example_02.java
 *
 * Copyright (c) 2026 PDFjet Software
 * Licensed under the MIT License. See LICENSE file in the project root.
 */
package examples;

import java.io.*;
import com.pdfjet.*;
import com.pdfjet.fonts.*;

/**
 * Example_02.java
 */
public class Example_02 {
    public Example_02() throws Exception {
        PDF pdf = new PDF(
                new BufferedOutputStream(new FileOutputStream("Example_02.pdf")));

        Font f1 = new Font(pdf, IBMPlexSansJP.Regular);
        f1.setSize(14f);

        Font f2 = new Font(pdf, IBMPlexSansKR.Regular);
        f2.setSize(14f);

        Font f3 = new Font(pdf, IBMPlexSansSC.Regular);
        f3.setSize(14f);

        Font f4 = new Font(pdf, IBMPlexSansTC.Regular);
        f4.setSize(14f);

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

        TextBlock textBlock = new TextBlock(
                f1, Content.ofTextFile("data/languages/japanese.txt"));
        textBlock.setLocation(50f, 50f);
        textBlock.setWidth(415f);
        textBlock.drawOn(page);

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

        textBlock = new TextBlock(
                f2, Content.ofTextFile("data/languages/korean.txt"));
        textBlock.setLocation(50f, 50f);
        textBlock.setWidth(415f);
        textBlock.drawOn(page);

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

        textBlock = new TextBlock(
                f3, Content.ofTextFile("data/languages/simplified-chinese.txt"));
        textBlock.setLocation(50f, 50f);
        textBlock.setWidth(415f);
        textBlock.drawOn(page);

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

        textBlock = new TextBlock(
                f4, Content.ofTextFile("data/languages/traditional-chinese.txt"));
        textBlock.setLocation(50f, 50f);
        textBlock.setWidth(415f);
        textBlock.drawOn(page);

        pdf.complete();
    }

    public static void main(String[] args) throws Exception {
        long time0 = System.currentTimeMillis();
        new Example_02();
        long time1 = System.currentTimeMillis();
        System.out.printf("Example_02 => %4d ms%n", time1 - time0);
    }
}   // End of Example_02.java

©2026 PDFjet Software.