Drawing Simplified and Traditional Chinese text with the embedded IBM Plex Sans SC and TC fonts, in a PDF/UA document.
Example_02.pdf — the PDF this example creates.
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")));
pdf.setCompliance(Compliance.PDF_UA_1);
pdf.setTitle("The Universal Declaration of Human Rights in Simplified and Traditional Chinese");
Font f0 = new Font(pdf, IBMPlexSans.Regular);
f0.setSize(12f);
// The .otf: a page of Chinese draws hundreds of glyphs, whose CFF
// outlines make a smaller subset than the .ttf's, about a quarter.
Font f1 = new Font(pdf, "fonts/IBMPlexSansSC/IBMPlexSansSC-Regular.otf");
f1.setSize(12f);
Font f2 = new Font(pdf, "fonts/IBMPlexSansTC/IBMPlexSansTC-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 names are
// escapes, so that the source stays ASCII.
// The line above each block is its heading
new TextLine(f0, "This block is Simplified Chinese: \u7b80\u4f53\u4e2d\u6587").setFallbackFont(f1)
.setStructureType(StructElem.H1).setLocation(50f, 50f).drawOn(page);
TextBlock textBlock = new TextBlock(
f1, Content.ofTextFile("data/languages/simplified-chinese.txt"));
textBlock.setLanguage("zh-Hans");
textBlock.setLocation(50f, 70f);
textBlock.setWidth(512f);
textBlock.drawOn(page);
page = new Page(pdf, Letter.PORTRAIT);
new TextLine(f0, "This block is Traditional Chinese: \u7e41\u9ad4\u4e2d\u6587").setFallbackFont(f2)
.setStructureType(StructElem.H1).setLocation(50f, 50f).drawOn(page);
textBlock = new TextBlock(
f2, Content.ofTextFile("data/languages/traditional-chinese.txt"));
textBlock.setLanguage("zh-Hant");
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_02();
long time1 = System.currentTimeMillis();
System.out.printf("Example_02 => %4d ms%n", time1 - time0);
}
} // End of Example_02.java
©2026 PDFjet Software.