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

PdfDocument UTF8 Character

I am using pdflightable in pdfdocmenr and set the font as
new PdfStandardFont(PdfFontFamily.Helvetica, 14, PdfFontStyle.Regular);
and when i export the pdf utf8 characters are blank, for example it does not export chinese characaters.
How to make the font support utf8 characters
Regards

5 Replies

GR Gayathri Ramalingam Syncfusion Team June 8, 2017 02:36 PM UTC

Hi Balasubramanian, 
Thank you for using Syncfusion product. 
We were able to reproduce the reported issue “Chinese character has not been preserved when we draw the PdfLighttable on PDF page”. Please find the code snippet and screen shot from below and conform to us whether you are facing same issue or not. 
Input XML file: 
<Products> 
    <Description1>111</Description1> 
    <Description2></Description2> 
    <Description3>III</Description3> 
  </Products> 
 
Code Snippet: 
 
// Create a new PDF document. 
 
PdfDocument doc = new PdfDocument(); 
 
//Add a page. 
 
PdfPage page = doc.Pages.Add(); 
 
//Acquire page's graphics. 
 
PdfGraphics graphics = page.Graphics; 
 
//Declare a PdfLightTable. 
 
PdfLightTable pdfLightTable = new PdfLightTable(); 
 
pdfLightTable.DataSource = //Get the data from Input XML file. 
 
pdfLightTable.Style.DefaultStyle = new PdfCellStyle(); 
 
pdfLightTable.Style.DefaultStyle.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 12f); 
 
//Draw the PdfLightTable. 
pdfLightTable.Draw(page, PointF.Empty); 
 
//Save the document. MemoryStream stream = new MemoryStream(); 
 document.Save(stream); 
 document.Close(true); 
 
if (stream != null) 
{ 
SaveiOS iosSave = new SaveiOS(); 
iosSave.Save("Output.pdf", "application/pdf", stream); 
} 
 
Please find the output document from the following link for your reference. 
 
Please let us know if you need further assistance on this. 
 
With Regards, 
Gayathri R 
 



BR Balasubramanian Ramanathan June 16, 2017 01:14 PM UTC

Hi,

Sorry for the late reply. Some how i did not get the notification for this thread.

I am doing the same thing as you have given in the sample code and having the same kind of result.

Is there a way to fix this?

Thank You


GR Gayathri Ramalingam Syncfusion Team June 19, 2017 12:39 PM UTC

Hi Balasubramanian,   
 
Thank you for your update. 
 
We could not draw UTF-8 characters using the PdfStandardFont, instead we can draw the UTF-8 by using PdfTrueTypeFont. The TTF file should be added to the project reference and inject the TTF stream via the PdfTrueTypeFont constructor. Using the below code you can get the stream value from .ttf file and you can set those font stream value to Font value of PdfLighttable. 
 
Please find the code snippet from below, 
Input XML file:  
<Products>     
    <Image>PDF</Image> 
    <Description>Essential PDF我我我我</Description> 
</Products> 
  
Code Snippet:  
  
// Create a new PDF document.  
  
PdfDocument doc = new PdfDocument();  
  
//Add a page.  
  
PdfPage page = doc.Pages.Add();  
  
//Acquire page's graphics.  
  
PdfGraphics graphics = page.Graphics;  
  
//Declare a PdfLightTable.  
  
PdfLightTable pdfLightTable = new PdfLightTable();  
  
pdfLightTable.DataSource = //Get the data from Input XML file.  
  
pdfLightTable.Style.DefaultStyle = new PdfCellStyle();  
 
Stream fontStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("jhenghei.ttf"); 
 
PdfTrueTypeFont font = new PdfTrueTypeFont(fontStream, 12); 
  
pdfLightTable.Style.DefaultStyle.Font = font;  
  
//Draw the PdfLightTable.  
pdfLightTable.Draw(page, PointF.Empty);  
  
//Save the document. MemoryStream stream = new MemoryStream();  
 document.Save(stream);  
 document.Close(true);  
  
if (stream != null)  
{  
SaveiOS iosSave = new SaveiOS();  
iosSave.Save("Output.pdf""application/pdf", stream);  
}  
  
 
Please find the output document from the following link for your reference.  
 
Please let us know if you need further assistance on this.  
  
With Regards,  
Gayathri R  
 
 
 



BR Balasubramanian Ramanathan June 20, 2017 01:01 AM UTC

Thank you for the reply. The specified font works for chinese characters.

Is there any open source TTF font thats support all the languages?

Thank You


KC Karthikeyan Chandrasekar Syncfusion Team June 20, 2017 12:32 PM UTC

Hi Balasubramanian, 
Thank you for your information, you may get more details about the open source true type fonts and its supported languages from the below link. 

Karthikeyan.C 


Loader.
Live Chat Icon For mobile
Up arrow icon