Free Support Forum - aspose.com

DOCX to PDF conversion issue with Arabic text rendering using .NET

Hi,

I have an HTML content that I insert into a document and the HTML content has italic parts in it. When I save the document as .docx it is fine, but when I save it as PDF the italic parts of the HTML is displayed as empty boxes.

  • However, if the font is “Arial Unicode MS” or “Andalus” the PDF is also fine. good.png (7.9 KB)
  • Problematic PDF is with the following fonts, there may be others as well:“Times New Roman”, “Arabic Typesetting”, “Dubai”, “Simplified Arabic”. bad.png (7.2 KB)

Attached is the code block to generate the problem, I am using the latest version of Aspose.Words, version 20.1:

    Private Sub Test1()
    Dim html As String = "<span>
                            <p style='text-align: right; direction: rtl;'>
	                            <i><span style='color: #db291d; font-size: 30px; text-align: start; word-spacing: normal;'>الفوائد</span></i>
                            </p>
                            <p style='text-align: right; direction: rtl;'>
	                            سهولة الوصول إلى كافة الأشرطة المادية والإلكترونية‬<br />
	                            ‫‬الحفاظ على جميع أفلام التسجيل والرسومات<br />
	                            <i>التخفيض من مخاطر التكنولوجيا والكوارث<br /></i>
                            </p>
                        </span>"

    Dim options As New Aspose.Words.Saving.PdfSaveOptions()
    'options.EmbedFullFonts = False
    'options.UseCoreFonts = True
    'options.FontEmbeddingMode =Aspose.Words.Saving.PdfFontEmbeddingMode.EmbedNonstandard

    '------------------------ FILE 1 ----------------------------------
    'Correct PDF with fonts: "Arial Unicode MS" and "Andalus"
    Dim doc As New Aspose.Words.Document()
    Dim builder As New Aspose.Words.DocumentBuilder(doc)
    builder.Font.Bidi = True
    builder.Font.LocaleIdBi = 1025
    builder.Font.Name = "Arial Unicode MS"
    builder.Font.NameBi = "Arial Unicode MS"
    builder.InsertHtml(html, True)

    Dim docx_path_1 As String = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Application.ExecutablePath), "Test-" + builder.Font.Name + ".docx")
    If System.IO.File.Exists(docx_path_1) Then
        System.IO.File.Delete(docx_path_1)
    End If
    doc.Save(docx_path_1)

    Dim pdf_path_1 As String = System.IO.Path.ChangeExtension(docx_path_1, ".pdf")
    If System.IO.File.Exists(pdf_path_1) Then
        System.IO.File.Delete(pdf_path_1)
    End If
    doc.Save(pdf_path_1, options)
    '------------------------------------------------------------------


    '------------------------ FILE 2 ----------------------------------
    'Incorrect PDF with fonts: "Times New Roman", "Arabic Typesetting", "Dubai", "Simplified Arabic" etc.
    Dim doc2 As New Aspose.Words.Document()
    Dim builder2 As New Aspose.Words.DocumentBuilder(doc2)
    builder2.Font.Bidi = True
    builder2.Font.LocaleIdBi = 1025
    builder2.Font.Name = "Times New Roman"
    builder2.Font.NameBi = "Times New Roman"
    builder2.InsertHtml(html, True)

    Dim docx_path_2 As String = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Application.ExecutablePath), "Test-" + builder2.Font.Name + ".docx")
    If System.IO.File.Exists(docx_path_2) Then
        System.IO.File.Delete(docx_path_2)
    End If
    doc2.Save(docx_path_2)

    Dim pdf_path_2 As String = System.IO.Path.ChangeExtension(docx_path_2, ".pdf")
    If System.IO.File.Exists(pdf_path_2) Then
        System.IO.File.Delete(pdf_path_2)
    End If
    doc2.Save(pdf_path_2, options)
    '------------------------------------------------------------------
End Sub

Thanks.

@serhatgulmez

Please note that Aspose.Words requires TrueType fonts when rendering document to fixed-page formats (JPEG, PNG, PDF or XPS). You need to install fonts that are used in your document on the machine where you are converting documents to PDF. Please refer to the following articles:

How Aspose.Words Uses True Type Fonts
How to Receive Notification of Missing Fonts and Font Substitution during Rendering

Please try the latest version of Aspose.Words for .NET 20.5. If you still face problem, please ZIP and attach these fonts here for testing? We will investigate the issue and provide you more information on it.

Hi Tahir,

The issue is resolved with Aspose.Words 20.5.

Thank you.

@serhatgulmez

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.