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 the 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 detail and will keep you updated on 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 at the following code snippet and sample PDF generated on my end.

[C#]

var pdfDocument = new Pdf();

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");

Good to know that adding the font name (arial unicode ms) is helping solve the problem.

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.

Hi Mohammad,

In reference to the fix for PDFNEWNET-37065, please use the new generator code below. It will help you accomplish the task.

string outFile = "37065.pdf";
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,