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

Free Support Forum - aspose.com

Arabic text in italics doesn't show up in pdf

Hello,

we are experiencing a problem when generating a pdf file from a Word document that contains italicized bidi text, Arabic in this case. The text appears fine in the Word doc but the pdf contains square boxes in place of the Arabic letters. I am not sure of this is just a font problem or something else.

We use Words.NET 13.3 but I have also tried 13.5 and this didn’t solve the problem.

I have attached a zip file that contains the Word and pdf files plus my small test program.

Hopefully you can help

Thanks.

Hi David,

Thanks for your inquiry. In your case, I suggest you please use the Font.NameBi and Font.LocaleIdBi properties to solve your problem as shown in following code snippet. Hope this helps you. Please let us know if you have any more queries.

Document _documentNode = new Document();
DocumentBuilder builder = new DocumentBuilder(_documentNode);
// Signal to Microsoft Word that this run of text contains right-to-left text.
builder.Font.Bidi = true;
//// Specify the font and font size to be used for the right-to-left text.
builder.Font.NameBi = "Andalus";
builder.Font.SizeBi = 14;
// Specify that the right-to-left text in this run is bold and italic.
builder.Font.ItalicBi = true;
builder.Font.BoldBi = true;
builder.Font.ItalicBi = true;
// Specify the locale so Microsoft Word recognizes this text as Arabic - Saudi Arabia.
// For the list of locale identifiers see http://www.microsoft.com/globaldev/reference/lcid-all.mspx
builder.Font.LocaleIdBi = 1025;
// Insert some Arabic text.
builder.Writeln("البتن لابتالتن الباني");
_documentNode.Save(MyDir + "Out.docx", SaveFormat.Docx);
_documentNode.Save(MyDir + "Out.pdf", SaveFormat.Pdf);

Hi Tahir,

thanks for your reply. Setting the fontBi name does indeed allow italics for Arabic. This was supposed to be a small test program to illustrate the problem. However, when I went back to our main code, it seems we use InsertHtml() rather than Writeln(). So if you replace the builder.Writeln() line with

_builder.InsertHtml("<i>البتن لابتالتن الباني</i>");

you will see that the pdf version of the document will not display the characters even though Word is ok. It would appear that the pdf generating code is not recognizing the tag to make the text italic.

Thanks

Hi David,

Thanks for your inquiry. Please note that, content inserted by DocumentBuilder.InsertHtml** method does not inherit formatting specified in DocumentBuilder options. Whole formatting is taken from HTML snippet. If you insert HTML with no formatting specified, then default formatting is used for inserted content.

In your case, I suggest you please use InsertHtmlWithBuilderFormatting instead of the InsertHtml method as shown in following code snippet. I have attached the code related to InsertHtmlWithBuilderFormatting with this post. Hope this helps you.

Document _documentNode = new Document();
DocumentBuilder builder = new DocumentBuilder(_documentNode);
// Signal to Microsoft Word that this run of text contains right-to-left text.
builder.Font.Bidi = true;
//// Specify the font and font size to be used for the right-to-left text.
builder.Font.NameBi = "Andalus";
builder.Font.SizeBi = 14;
// Specify that the right-to-left text in this run is bold and italic.
builder.Font.ItalicBi = true;
builder.Font.BoldBi = true;
builder.Font.ItalicBi = true;
// Specify the locale so Microsoft Word recognizes this text as Arabic - Saudi Arabia.
// For the list of locale identifiers see http://www.microsoft.com/globaldev/reference/lcid-all.mspx
builder.Font.LocaleIdBi = 1025;
InsertHtmlWithBuilderFormatting(builder, "البتن لابتالتن الباني"); 
_documentNode.Save(MyDir + "Out.docx", SaveFormat.Docx);
_documentNode.Save(MyDir + "Out.pdf", SaveFormat.Pdf);