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

PDF cannot render strings in some languages (Chinese simplified, Japanese)

using the PdfGraphics "DrawSring" method, I'm passing in a unicode string that looks like this (for Chinese simplified):


过去 7 天内的血糖平均 : 111.37 mg/dL

this renders properly everywhere, including on the graph titles and axis and such, but the PDF control only allows for 5 fonts to be passed to the DrawString as the PdfFont parameter - I tried all 5 and the above string renders in the PDF output as:

7 : 111.37 mg/dL

For other languages like German, French, Spanish etc... it renders fine, of course - just graphical languages that require special fonts - Word uses "Microsoft JhengHei" for this, it can also use "MS Gothic" and the like.  

Just checking if there's something simple I'm missing or if the PDF component does not support rendering strings for all languages.

thanks


11 Replies

SK Sasi Kumar Sekar Syncfusion Team October 18, 2016 02:20 PM UTC

Hi Jeff, 

Thank you for contacting Syncfusion support, 

We can draw the text using different font using the PdfTruetypeFont, please find the below code snippet to load the different font file to PdfTrueTypeFont to draw the string. 
 
Stream fontStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("jhenghei.ttf");  PdfTrueTypeFont font = new PdfTrueTypeFont(fontStream, 12); 
page.Graphics.DrawString("过去 7 天内的血糖平均", font, PdfBrushes.Black, new PointF(10, 10)); 
 

We have created the sample to preserve the given Chinese character by mentioned  JhengHei TrueType Font file. Please find the sample link below for your reference. 
Sample link: 

Please let us know if you have need further assistance. 
Regards, 
Sasi kumar S. 



JL Jeff Lindborg October 18, 2016 04:16 PM UTC

cool - the arialuni.ttf font included in your sample project works for all languages I tried it against (Hindi, Arabic, Japanese, Chinese simplified) - so that will work out find.

thanks much.


SK Sasi Kumar Sekar Syncfusion Team October 19, 2016 07:16 AM UTC

Hi Jeff, 
Thank you for your update, 
Please let us know if you need further assistance. 
Regards, 
Sasi kumar S. 



SB Slobodan Babic June 2, 2017 11:24 AM UTC

Hello.
I am having a similar issue while working with PDF files, only difference is that contain text form fields - some specific Unicode characters are not rendering properly when using PdfStandardFont.
Can I somehow set the font property for textual form field, and then use PdfTrueTypeFont that I obtained from resources for fields?


SK Sasi Kumar Sekar Syncfusion Team June 5, 2017 06:16 AM UTC

Hi Jeff, 
 
Thank you for your update, 
 
In default the PDF Standard fonts is not supported for all Unicode characters, we have preferred the Truetype fonts to preserve the Unicode characters. Please find the UG documentation link for embedding and working with the Unicode character. 
 
UG documentation link: 
 
We can set the font for the specific form field by using the Font property. Please find the code snippet to set font to the form field. 
Code snippet: 
//Create a new PDF document. 
PdfDocument document = new PdfDocument(); 
 
//Add a new page to the PDF document. 
PdfPage page = document.Pages.Add(); 
 
//Create a textbox field and add the properties. 
PdfTextBoxField textBoxField = new PdfTextBoxField(page, "CompanyName"); 
  
Stream fontStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("jhenghei.ttf"); 
 
PdfTrueTypeFont font = new PdfTrueTypeFont(fontStream, 12);  
 
//Set the font to the form field. 
textBoxField.Font = font; 
 
textBoxField.Text = "Syncfusion"; 
 
textBoxField.Bounds = new RectangleF(0, 0, 100, 20); 
 
textBoxField.ToolTip = "First Name"; 
 
//Add the form field to the document. 
document.Form.Fields.Add(textBoxField); 
 
MemoryStream stream = new MemoryStream(); 
document.Save(stream); 
 
Please let us know If you need further assistance in this. 
 
Regards, 
Sasi Kumar S. 



EL Elke August 27, 2019 06:02 AM UTC

Hi, 
I have a similar issue. I am creating a pdf and I want/need to use the free google font noto. So with latin characters everything works fine, but when I try chinese or japan characters the pdf stays empty. The font I am using includes the characters.
I set the font as described in the post below. 
When I use PdfCjkStandardFont with eg HeiseiMinchoW3 everything works fine. 

Can you help me?

Here you get the font: https://www.google.com/get/noto/ - I tried all 4 different CJK-font files and none of them work. 
I am testing with Xamarin at iOS. 


SL Sowmiya Loganathan Syncfusion Team August 28, 2019 11:13 AM UTC

Hi Elke, 

Greetings from Syncfusion. 

While creating PDF document with Japanese/Chinese characters, kindly use the font file which supports that languages. We have tried this in our end with the google noto fonts (supports Japanese/Chinese languages), it preserves the text in resultant PDF document. Please find the code snippet for your reference,  

Code snippet: 
//Create a new PDF document. 
PdfDocument document = new PdfDocument(); 
 
//Add a new page to the PDF document.  
PdfPage page = document.Pages.Add(); 
 
//Create PDF graphics for the page. 
PdfGraphics graphics = page.Graphics; 
 
//Load the open type font.  
Stream fontStream = typeof(MainPage).GetTypeInfo().Assembly.GetManifestResourceStream("Sample.Assets.NotoSerifCJKjp-Regular.otf"); 
 
PdfTrueTypeFont font = new PdfTrueTypeFont(fontStream, 14); 
 
//Draw the text. 
graphics.DrawString("你好,世界", font, PdfBrushes.Black, new PointF(0, 0)); 
 
graphics.DrawString("こんにちは世界", font, PdfBrushes.Black, new PointF(0, 50)); 
 
//Save the document to the stream 
MemoryStream stream = new MemoryStream(); 
document.Save(stream); 
 
//Close the document 
document.Close(true); 
 

Screenshot: 
 

Please find the font file names which we have tried from below, 
  • NotoSansCJKjp
  • NotoSansCJKsc
  • NotoSerifCJKjp

Please find the output documents from below, 

Please try the above code snippet with the mentioned font files in your end and let us know if it solves the issue. Could please share us the font file which does not preserves the Japanese/Chinese characters, it will helpful for us to provide the precise solution on this.  

Regards, 
Sowmiya L 



EL Elke August 28, 2019 01:21 PM UTC

Thanks a lot for your help - my problem was, that I was using Version 16.3.0.21. With an update to the newest Version (17.2.0.47) it works fine. 


SL Sowmiya Loganathan Syncfusion Team August 29, 2019 10:17 AM UTC

Hi Elke, 
  
Thank you for the update. We glad to know that the issue resolved in latest version 17.2.0.47.  
  
Regards, 
Sowmiya L 



BY BAO YADONG December 27, 2019 06:04 AM UTC

Hi Sowmiya,

We managed to do the same with Google fonts and the resulting pdf is too big as it is more than 10Mb even for only a few lines. 
I can see the same in your sample. Is there any way to enhance this to reduce the file size? 


SL Sowmiya Loganathan Syncfusion Team December 30, 2019 12:26 PM UTC

Hi BAO, 

We have analyzed the issue which you have mentioned. While creating PDF with OTF fonts, we have embedded the font file into PDF document. So depends on the font file size, resultant PDF document size will increase. To overcome this issue, kindly use the small size font file to draw the text in PDF document.  

Please let us know if you have any concerns on this.  

Regards, 
Sowmiya Loganathan 


Loader.
Up arrow icon