Drawing Japanese and Korean text with the embedded IBM Plex Sans JP and KR fonts, in a PDF/UA document.
Example_03.pdf — the PDF this example creates.
package examples;
import java.io.*;
import com.pdfjet.*;
import com.pdfjet.fonts.*;
/**
* Example_03.java
*/
public class Example_03 {
public Example_03() throws Exception {
PDF pdf = new PDF(
new BufferedOutputStream(new FileOutputStream("Example_03.pdf")));
pdf.setCompliance(Compliance.PDF_UA_1);
pdf.setTitle("The Universal Declaration of Human Rights in Japanese and Korean");
Font f0 = new Font(pdf, IBMPlexSans.Regular);
f0.setSize(12f);
// The .otf: a page of Japanese or Korean draws hundreds of glyphs, whose CFF
// outlines make a smaller subset than the .ttf's, about a quarter.
Font f1 = new Font(pdf, "fonts/IBMPlexSansJP/IBMPlexSansJP-Regular.otf");
f1.setSize(12f);
Font f2 = new Font(pdf, "fonts/IBMPlexSansKR/IBMPlexSansKR-Regular.otf");
f2.setSize(12f);
Page page = new Page(pdf, Letter.PORTRAIT);
// The heading is in IBM Plex Sans, and the characters it has no glyph for,
// the name of the language, are in the fallback font.
// The line above each block is its heading
new TextLine(f0, "This block is Japanese: \u65e5\u672c\u8a9e").setFallbackFont(f1)
.setStructureType(StructElem.H1).setLocation(50f, 50f).drawOn(page);
TextBlock textBlock = new TextBlock(
f1, Content.ofTextFile("data/languages/japanese.txt"));
textBlock.setLanguage("ja");
textBlock.setLocation(50f, 70f);
textBlock.setWidth(512f);
textBlock.drawOn(page);
page = new Page(pdf, Letter.PORTRAIT);
new TextLine(f0, "This block is Korean: \ud55c\uad6d\uc5b4").setFallbackFont(f2)
.setStructureType(StructElem.H1).setLocation(50f, 50f).drawOn(page);
textBlock = new TextBlock(
f2, Content.ofTextFile("data/languages/korean.txt"));
textBlock.setLanguage("ko");
textBlock.setLocation(50f, 70f);
textBlock.setWidth(512f);
textBlock.drawOn(page);
pdf.complete();
}
public static void main(String[] args) throws Exception {
long time0 = System.currentTimeMillis();
new Example_03();
long time1 = System.currentTimeMillis();
System.out.printf("Example_03 => %4d ms%n", time1 - time0);
}
} // End of Example_03.java
©2026 PDFjet Software.