PDFSharp with Chinese characters

2019-07-14 07:31发布

问题:

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. I found one solution which is

XFont font_small2 = new XFont("微软雅黑", 9, XFontStyle.Regular, options)

This solutions works on my localhost but when I release this on beta server it doesn't display Chinese characters.

回答1:

You can embed original Chinese font into your pdf file and use correct CMAP.

var options = new XPdfFontOptions(PdfFontEmbedding.Always);
var font = new XFont("微软雅黑", 9, XFontStyle.Regular, options);

OR

var page = new PdfPage();
var gfx = XGraphics.FromPdfPage(page);
gfx.MFEH = PdfFontEmbedding.Automatic;


回答2:

Make sure the font is installed correctly on the beta server and make sure application has sufficient rights. Make sure the font is embedded in the PDF file.

According to the PDFsharp FAQ, CJK fonts are not supported. But still you should get the same results on server and local computer if the environments are set up correctly.