We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Display of unicode text inside a grid

I am using PDFGrid for data display and would like to display Chinese characters along with English text. I found that using PDFTrueTypeFont the Chinese characters are not shown while using PdfCjkStandardFont would make the English text messed up, e.g.



Here is the code snippet for the above PDF:

        private static void _createPDF(string filename)
        {
            var pdf = new PdfDocument();
            var page = pdf.Pages.Add();
            var table = new PdfGrid();
            table.Columns.Add(2);

            var font1 = new PdfTrueTypeFont(new Font("Arial", 14f), true);
            var font2 = new PdfCjkStandardFont(PdfCjkFontFamily.HeiseiMinchoW3, 14f);
            _addTestContent(table, "One Two Three").Style.Font = font1;
            _addTestContent(table, "One Two Three").Style.Font = font2;
            _addTestContent(table, "一二三").Style.Font = font1;
            _addTestContent(table, "一二三").Style.Font = font2;
            _addTestContent(table, "One Two Three 一二三").Style.Font = font1;
            _addTestContent(table, "One Two Three 一二三").Style.Font = font2;

            table.Draw(page, new PointF(0f, 0f));
            using (var f = new FileStream(filename, FileMode.Create))
            {
                pdf.Save(f);
            }
        }

        private static PdfGridRow _addTestContent(PdfGrid table, string value)
        {
            var row = table.Rows.Add();
            row.Cells[0].Value = table.Rows.Count().ToString();
            row.Cells[1].Value = value;
            return row;
        }

Also I would like to know if it is possible to embed the CJK font used in the PDF file?

5 Replies

KK Karthik Krishnaraj Syncfusion Team July 15, 2015 01:29 PM UTC

Hi William,

Thank you for using syncfusion products,

We have tried to reproduce the issue with "Text messed up" as per your provided code snippet, but it works in our end. I have attached the output pdf document for your reference. Since Arial font doesn’t support Unicode characters, the text will not be drawn. Can you please let us know your assembly version, System environment details ,OS details and culture settings? so that it will be helpful for us to investigate further.

Output Document:
http://www.syncfusion.com/downloads/support/forum/119608/ze/CJKFont867715499
Thanks,
Karthik.


WW William Wong July 16, 2015 02:54 AM UTC

Thank you very much for you time in testing the issue. That's it! I always forget about non all true type fonts are unicode enabled! Using "Arial Unicode MS" solved the problem for me. However the CJK font output is still messy at displaying English text and I wonder when should I use the CJK fonts? Since my PDF output essentially consists of a large PDFGrid only, is there any way to embed the font into the PDF file for better compatibility? FYI, the sample I created was a console application using nuget package of the Syncfusion.Pdf.Windows.451 package and its defendant packages. The assembly files linked are:

Syncfusion.Compression.Base 13.2451.0.29
Syncfusion.Pdf.base 13.2451.0.29
Syncfusion.Pdf.Windows 13.2451.0.29

My PC is a Windows 8.1 x64 and the default locale is en-US.


KK Karthik Krishnaraj Syncfusion Team July 16, 2015 11:06 AM UTC

Hi William,
Thank you for your update,
I wonder when should I use the CJK fonts?
If you use Chinese, Japanese or Korean languages, you can use CJK fonts.
Is there any way to embed the font into the PDF file for better compatibility?
It is not necessary to embed the CJK fonts in to the PDF document, since adobe itself having the standard CJK fonts in built.

If you want to embed the true type fonts, then you need to set true for Unicode parameter while using PdfTrueTypeFont.

Code Snippet:
PdfFont font1 = new PdfTrueTypeFont(new Font("Arial", 14f), true);

However the CJK font output is still messy at displaying English text
It is not recommended to use CJK fonts for English characters. Also make sure that the CJK packages are installed properly in your machine. Try installing the adobe reader multilingual package

http://www.adobe.com/support/downloads/detail.jsp?ftpID=5507

Thanks,
Karthik.


WW William Wong July 17, 2015 09:41 AM UTC

Thank you very much for your answers. The previous screenshot was taken from Acrobat Pro 9 with Asian fonts pack installed quite some time ago. After installing the latest Acrobat Reader DC and the multilingual package required, the English text are shown correctly in the Reader... even in the original Acrobat Pro 9.


KK Karthik Krishnaraj Syncfusion Team July 20, 2015 08:39 AM UTC

Hi William,
Thank you for your update,
We are happy to hear that your issue has been resolved, please let me know if you have any other queries.
Thanks,
Karthik.

Loader.
Live Chat Icon For mobile
Up arrow icon