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.
using System;
using System.IO;
using System.Diagnostics;
using PDFjet.NET;
/**
* Example_02.cs
*/
public class Example_02 {
public Example_02() {
PDF pdf = new PDF(new BufferedStream(
new FileStream("Example_02.pdf", FileMode.Create)));
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 line above each block is its heading
new TextLine(f0, "This block is Simplified Chinese: 简体中文").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: 繁體中文").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) {
Stopwatch sw = Stopwatch.StartNew();
long time0 = sw.ElapsedMilliseconds;
new Example_02();
long time1 = sw.ElapsedMilliseconds;
sw.Stop();
Console.WriteLine($"Example_02 => {time1 - time0,4} ms");
}
} // End of Example_02.cs
©2026 PDFjet Software.