Non english chars arent displayed

Hi,

When i create pdf with grid , text with turkish chars arent displayed . How can i achieve this ?

Thanks 

5 Replies

KC Karthikeyan Chandrasekar Syncfusion Team September 3, 2018 07:09 AM UTC

Hi Emil, 
By default PdfGrid use Helvetica font for rendering the text in the cells. This font do not have support for drawing all the Turkish characters. So you have to use the font which supports the Turkish characters from the application level. Below is the code snippet for applying the custom TTF font to the PdfGrid. 

//Create a new PDF document. 
PdfDocument doc = new PdfDocument(); 
 
//Add a page. 
PdfPage page = doc.Pages.Add(); 
 
//Create a PdfGrid. 
PdfGrid pdfGrid = new PdfGrid(); 
Stream fontStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("Demo.Assets.arial.ttf"); 
 
pdfGrid.Style.Font = new PdfTrueTypeFont(fontStream, 12); 
 
//Create a DataTable. 
DataTable dataTable = new DataTable(); 
//Add columns to the DataTable 
dataTable.Columns.Add("ID"); 
dataTable.Columns.Add("Name"); 
//Add rows to the DataTable. 
dataTable.Rows.Add(new object[] { "E01", "ŞĞÇÜÖ" }); 
dataTable.Rows.Add(new object[] { "E02", "Selam Dünya" }); 
 
//Assign data source. 
pdfGrid.DataSource = dataTable; 
 
//Draw grid to the page of PDF document. 
pdfGrid.Draw(page, new PointF(10, 10)); 
 
//Save the document. 
doc.Save(memoryStream); 
//close the document 
doc.Close(true); 
 
To get more details on how to apply the custom fonts, read the similar blog below which describes adding the font in to Xamarin Application. 

Regards, 
Karthikeyan 



EM Emil September 8, 2018 09:42 PM UTC

it is not clear for me. do we have to download arial.ttf and embed into our .net standard project? I saw that those fonts have large size. they increase our app size. is it correct or there is some workaround for it?



KC Karthikeyan Chandrasekar Syncfusion Team September 10, 2018 12:11 PM UTC

Hi Emil, 
Yes, you have to place the TTF file in the application to get it included in the PDF document. However, we have an optional workaround to get the TTF directly from the device at runtime using open source third party library SkiaSharp. Please refer the below code example for further details. 

             
            //Create new PDF document. 
            PdfDocument doc = new PdfDocument();           
 
            //Add page to the PDF document. 
            PdfPage page = doc.Pages.Add();             
 
            //Get font from device using Skia Sharp. 
            Stream fontStream = GetFontStream("Arial Unicode Ms"); 
 
            //Create new PdfTrueTypeFont instance. 
            PdfTrueTypeFont font = new PdfTrueTypeFont(fontStream, 12); 
 
            //Draw text. 
            page.Graphics.DrawString("Наименование", font, PdfBrushes.Black, PointF.Empty); 
 
            MemoryStream stream = new MemoryStream(); 
 
            //Save the PDF document 
            doc.Save(stream); 
 
            //Close the PDF document 
            doc.Close(true); 
 

 
private Stream GetFontStream(string fontName) 
        { 
            SKTypeface typeface = SKTypeface.FromFamilyName("Arial Unicode Ms", SKTypefaceStyle.Normal); 
            SKStreamAsset stream = typeface.OpenStream(); 
            if (stream != null && stream.Length > 0) 
            { 
                byte[] fontData = new byte[stream.Length - 1]; 
                stream.Read(fontData, stream.Length); 
                stream.Dispose(); 
                return new MemoryStream(fontData); 
            } 
            else 
                return null; 
        } 
 
Regards, 
Karthikeyan 



EM Emil September 16, 2018 10:55 PM UTC

i am getting null result on the function below when I try on andorid emulator. Is that Arial Unicode Ms recognized by all devices of Andorid, IOS and UWP?

 SKTypeface typeface = SKTypeface.FromFamilyName("Arial Unicode Ms", SKTypefaceStyle.Normal);

I am using SkiaSharp Version 1.6.0



KC Karthikeyan Chandrasekar Syncfusion Team September 17, 2018 11:49 AM UTC

Hi Emil, 
Yes, we are able to reproduce the reported behavior in Android emulator and it is the behavior of SkiaSharp. As per the SkiaSharp documentation the GetFontFamilyName returns a new instance to a typeface that most closely matches the requested family name and style. 
 
SkiaSharp Documentation link:  
 
Suspecting that there is no matching font family “Arial Unicode Ms” in the emulator. I have used same code snippet in Xamarin.Forms.UWP, GetFontFamilyName returns as “Arial Uicode Ms”, So we have to suggest the substitution font, if SkTypeface is null to overcome this behavior. 
 
Please let me know if you have any concern on this. 
Regards, 
Karthikeyan 


Loader.
Up arrow icon