Frequently Asked Question:
Adding PRC unicode strings into Quick PDF
I need to be able to generate PDF's files with Simplified Chinese characters. I have tried a couple of things but cannot get it to work.
For example:
String Font = "Arial [Bold] {936}";
int id = qp.AddTrueTypeFont(font, 936);
qp.SelectFont(id);
qp.DrawText(100, 100, ChineseText);
But all I get is garbage.
What is the correct way of doing this?
Quick PDF Library currently only supports 8-bit fonts.
There is support for 16-bit CJK fonts, but only the Japanese font "HeiseiKakuGo-W5" has been implemented.
QPL's font subsetting functionality can be used to draw Chinese text though.
The first step is to call the AddSubsettedFont function giving a font name, specifying the character set and a list of characters to subset.
Up to 255 characters can be placed into each subsetted font.
Then the usual text drawing functions can be used - but the Unicode characters must first be mapped to 8-bit character codes using the GetSubsetString function.
Here's an example written in C#:
// Subset a few characters from the Arial font
// using the CHINESEBIG5_CHARSET character set
qp.AddSubsettedFont("Arial", 7, "ä½ å¥½ä¸–ç•Œ");
// Convert the Unicode text to 8-bit characters and draw them onto the page
qp.DrawText(100, 500, qp.GetSubsetString("ä½ å¥½ä¸–ç•Œ"));