I have problem with displaying Chinese characters in PDFSharp in C#. During process of creating the PDF string it\'s ok, but after creating pdf file it doesn\'t display it.
Neither of the solutions worked for a newer version of the lib, so I came up with a workaround on drawing chars to a bitmap, then adding the bitmap to a PDF:
Font font = GetFont(fieldInfo, fontSize * 0.97f); // Chosen empirically
using (var imageStream = new MemoryStream())
{
// Draw string as an image
using (var bitmap = new Bitmap((int) fieldRect.Width, (int) (fieldRect.Height * 1.5f)))
using (Graphics graphics = Graphics.FromImage(bitmap))
{
graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
graphics.DrawString(fieldValue, font, Brushes.Black, PointF.Empty);
bitmap.Save(imageStream, ImageFormat.Png);
}
// Draw image on PDF
using (XImage xImage = XImage.FromStream(imageStream))
{
double labelPositionX = fieldRect.X1 + 2;
double labelPositionY = fieldRect.Y2 - 2;
xGraphics.DrawImage(xImage, labelPositionX, page.Height - labelPositionY);
}
}