How to add support for Chinese Font with aspose.net

hi,

I’m working with aspose.net and found it’s not support unicode, i know there are pdf.SetUnicode() method in Aspose.Pdf.Generator API.
but i want to know that is there a method like “setUnicode” for support unicode or Chinese Font in Aspose.Pdf API

Hi Jeff,


Thanks for your inquiry. Aspose.Pdf supports multi language chars along with Chinese. However the font should be available on the host machine. You may use Arial Unicode MS font as it supports the characters. Please check following code sample snippet for the purpose. Hopefully it will help you to accomplish the task.


Document textdoc = new Document();<o:p></o:p>

Page page = textdoc.Pages.Add();<o:p></o:p>

//Chinese<o:p></o:p>

TextFragment textc = new TextFragment(“The Chinese Text Project (CTP; Chinese: 中國哲學書電子化計劃) is a digital library project”);<o:p></o:p>

//Set text properties<o:p></o:p>

textc.TextState.FontSize = 8;<o:p></o:p>

textc.TextState.Font = FontRepository.FindFont(“Arial Unicode MS”);<o:p></o:p>

//Add a new text paragraph in paragraphs collection and pass the TextFramment object<o:p></o:p>

page.Paragraphs.Add(textc);<o:p></o:p>

//Save resultant PDF file<o:p></o:p>

textdoc.Save(myDir + “TextPDF.pdf”);<o:p></o:p>

<o:p>Please feel free to contact us for any further assistance.</o:p>

<o:p>
</o:p>

<o:p>Best Regards,</o:p>

Hi,


Thanks for you reply, and further question is that i need to set the font each time when a add table or text fragment.
Did you provide a api to set the font at page level?

Hi Jeff,


Thanks for your inquiry. Yes you can set a document level font as following. Hopefully it will help you to accomplish the task.

Document doc = new
Document();

Aspose.Pdf.Text.Font font = Aspose.Pdf.Text.FontRepository.FindFont(“Arial”);

doc.PageInfo.DefaultTextState.Font = font;


Please feel free to contact us for any further assistance.

Best Regards,

Hi,

Thanks for you help. And further question is that:
Is there any ideas to support CJK fonts in a server which no “Arial Unicode MS” installed.

Aspose.Pdf.Text.FontRepository.FindFont(“Arial”); will throw exception. how to deal with it, try catch?

and i have a little confused because same words like “賬戶” “說明” display normally in word or pdf which i created, but garbled in pdf generated using API at the same server( no “Arial Unicode MS” installed.)
What’s the different?

Actually i migrate the PDF control from PDFTechLib to Aspose.PDF
and thecode snippet in PDFTechLib is
  • if (resMgr.LanguageID == “CHS”)
  • Page.Body.SetCjkFont(CJKFonts.SinoTypeSongLight, PDFFontStyles.Bold, 10);
  • else if (resMgr.LanguageID == “CHT”)
  • Page.Body.SetCjkFont(CJKFonts.MonotypeHeiMedium, PDFFontStyles.Bold, 10);
  • else
  • Page.Body.SetActiveFont(“Arial”, PDFFontStyles.Bold, 10, CharSet, Color.Black);

How to implement this logic using aspose.pdf?

Hi Jeff,


Thanks for your inquiry. Please get installed CJK fonts on the server and use it via FindFont() method, it will help you to use it.

Please note FindFont does not throw the exception but it fallback to system default font, so you are getting issue with some characters. We have already logged a request(PDFNEWNET-38747) to set custom fallback font in case API does not find the referred font.

Moreover, you can create different font objects and set DefaultTextState properties as per LanguageID variable value.

If there is any difference in my understanding and your requirement then please share some more details, so we will guide you accordingly.

Best Regards,

Dear Sirs


I got a request to implement the reporting feature in our application. I am wondering if Aspose still supported the reporting feature? I remember it did before.




Best Regards

Jeff

Hi Jeff,


Thanks for contacting support.

From reporting feature, do you mean support for converting .RDL files using SQL Reporting Services or creation of reports in .NET code using tables and textual information. Please share the details, so we may reply accordingly.