We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to convert Persian Or Arabic words?

Hi


I’m using Aspose.Pdf for exporting report to PDF. but report is in Arabic and when I download the generated PDF it’s content is like “س ل م” and every word is separated, but it must be like “سلام”. how can I solve this issue ?


my code for generating PDF :

public static void ExportReportToPdf(DTO.Report.Report report)
{
var pdfDocument = new Pdf();

pdfDocument.HtmlInfo.CharSet = “UTF-8”;

pdfDocument.HtmlInfo.CharsetApplyingLevelOfForce = HtmlInfo.CharsetApplyingForceLevel.UseWhenImpossibleDetectFromContent;

var pdfSection = pdfDocument.Sections.Add();

pdfSection.TextInfo.FontEncoding = “UTF-8”;

pdfDocument.TextInfo.FontEncoding = “UTF-8”;

pdfSection.Paragraphs.Add(new Text(report.Title));

pdfSection.Paragraphs.Add(new Text(report.DateTime.ToShortDateString()));

var text = new Text(pdfSection, report.Description) {IsHtmlTagSupported = true};

pdfSection.Paragraphs.Add(text);

pdfDocument.Save(HttpContext.Current.Server.MapPath("~/Content/report/temp.pdf"));

}

Hi Mohammad Reza,.


Thanks for contacting support.

In order to render Right to Left languages (Urdu, Arabic, Persian etc), you need to set the value of text.TextInfo.IsRightToLeft as true;. However I have observed that when using IsHtmlTagSupported as True, the Arabic contents are not appearing in correct manner (characters appearing in reverse order and they are not appearing as single word). For
the sake of correction, I have logged it in our issue tracking system as PDFNEWNET-37065. We will
investigate this issue in details and will keep you updated on the status of a
correction. We
apologize for your inconvenience.

However if you set the value of IsHtmlTagSupported as False, the contents appear properly. Please take a look over following code snippet and sample PDF generated over my end.

[C#]

var pdfDocument = new Pdf();<o:p></o:p>

var pdfSection = pdfDocument.Sections.Add();

pdfSection.TextInfo.FontEncoding = "UTF-8";

pdfDocument.TextInfo.FontEncoding = "UTF-8";

pdfSection.Paragraphs.Add(new Text("report.Title"));

pdfSection.Paragraphs.Add(new Text("report.DateTime.ToShortDateString()"));

var text = new Text("سلام"){ IsHtmlTagSupported = false };

text.TextInfo.IsRightToLeft = true;

// set font as Arial Unicode MS as it supports Non-English characters

text.TextInfo.FontName = "Arial Unicode MS";

pdfSection.Paragraphs.Add(text);

// embed unicode font subset in PDF

pdfDocument.SetUnicode();

pdfDocument.Save("c:/pdftest/Arabic_Persian_test.pdf");

Thank you, I have done as you said but the problem still exist :((


When IsHtmlTagSupported = true then all text content will be separated but when it is FALSE then content is like usual and correct !
ipazooki:
Thank you, I have done as you said but the problem still exist :((

When IsHtmlTagSupported = true then all text content will be separated but when it is FALSE then content is like usual and correct !
Hi Mohammad Reza,

As shared above, this problem is logged in our issue tracking system as PDFNEWNET-37065. We will further look into this problem and will keep you posted on the status of correction. Please be patient and spare us little time.

The issues you have found earlier (filed as PDFNEWNET-37065) have been fixed in Aspose.Pdf for .NET 9.6.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Hi Mohammad,


In reference to above stated fix of PDFNEWNET-37065, please use new generator code as following. It will help you to accomplish the task.

string outFile = “37065.pdf”;<o:p></o:p>

Document doc = new Document();

Page page = doc.Pages.Add();

TextFragment text = new TextFragment("سلام");

text.TextState.Font = FontRepository.FindFont("Arial Unicode MS");

page.Paragraphs.Add(text);

doc.Save(outFile);

Please feel free to contact us for any further assistance.


Best Regards,