question

MafievDev-0618 avatar image
0 Votes"
MafievDev-0618 asked JackJJun-MSFT commented

How do I display Chinese text in PDF using ASP.NET?

I need to generate a PDF document with some Chinese text in it in .NET C#, but when i create it it shows (????) and not Chinese letters.. what should i do ?

dotnet-csharp
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@MafievDev-0618, I think MoDeveloper's solution is good, do you have any question?

0 Votes 0 ·

1 Answer

MoDeveloper avatar image
0 Votes"
MoDeveloper answered

First, make sure that your computer supports the Chinese language and download the needed fonts if they are not installed

Second, you need to use a PDF generation library...
I use PDFFlow library and it's very simple to add Chinese text, you just need to change the encoding of the text,

this is an example to get Chinese text in PDF docs:

 DocumentBuilder.New().AddSection() 
 .AddParagraph("Chinese text: 世界你好文本在这里")  
 .SetFontEncodingName(EncodingNamesChineseSimplified.GBK_EUC_H) 
 .SetFontName(FontNamesChineseSimplified.SimHei).ToDocument() 
 .Build("chinesetext.pdf"); 


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.