Category / Section
How to draw a Unicode characters in PDF document in ASP.NET Core platform?
1 min read
You can render Unicode text by adding custom fonts in .NET Core PDF document by using PdfTrueTypeFont instance in ASP.NET core platform. Refer the below code example for further details.
//Create a new PDF document PdfDocument document = new PdfDocument(); //Add a page to the document. PdfPage page = document.Pages.Add(); //Create PDF graphics for the page. PdfGraphics graphics = page.Graphics; string path = _hostingEnvironment.WebRootPath + "/Font/Arial.ttf"; Stream fontStream = new FileStream(path, FileMode.Open, FileAccess.ReadWrite); //Create a new PDF true type font. PdfTrueTypeFont tFont = new PdfTrueTypeFont(fontStream, 12, PdfFontStyle.Regular); //Draw the text graphics.DrawString("Sample@#% unicode test%3^*", tFont, PdfBrushes.Black, Syncfusion.Drawing.PointF.Empty); MemoryStream ms = new MemoryStream(); //Save the PDF document document.Save(ms); //Close the dococument document.Close(true);
Sample link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/WebApplication-1079519555