Right-to-Left Text

With GemBox.Document, you can work with documents that contain bidirectional texts. This includes languages that use right-to-left scripts such as Arabic, Persian, Urdu, Hebrew and Yiddish.

Besides read and write support for Word documents with bidirectional text, GemBox.Document supports rendering such text to PDF, XPS and image formats.

You can customize the direction of document elements by using the following properties:

The following example shows how you can convert a document with bidirectional text to PDF or other file format.

Word document with right-to-left text converted to PDF file
Screenshot of converted PDF with right-to-left text
Upload your file (Drag file here)
using GemBox.Document;
using GemBox.Document.Tables;

class Program
{
    static void Main()
    {
        // If using the Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        var document = DocumentModel.Load("%InputFileName%");

        // Show line numbers on the right side of the page
        var pageSetup = document.Sections[0].PageSetup;
        pageSetup.LineNumberRestartSetting = LineNumberRestartSetting.Continuous;
        pageSetup.RightToLeft = true;

        // Create a new right-to-left paragraph
        var paragraph = new Paragraph(document);
        paragraph.ParagraphFormat.RightToLeft = true;
        paragraph.Inlines.Add(new Run(document, "أخذ عن موالية الإمتعاض"));
        document.Sections[0].Blocks.Add(paragraph);

        // Create a right-to-left table
        var table = new Table(document);
        table.TableFormat.RightToLeft = true;
        table.TableFormat.PreferredWidth = new TableWidth(100, TableWidthUnit.Percentage);
        var row = new TableRow(document);
        table.Rows.Add(row);

        var firstCellPara = new Paragraph(document, "של תיבת תרומה מלא");
        firstCellPara.ParagraphFormat.RightToLeft = true;
        row.Cells.Add(new TableCell(document, firstCellPara));

        var secondCellPara = new Paragraph(document, "200");
        row.Cells.Add(new TableCell(document, secondCellPara));

        document.Sections[0].Blocks.Add(table);

        document.Save("RightToLeft.%OutputFileType%");
    }
}
Imports GemBox.Document
Imports GemBox.Document.Tables

Module Program

    Sub Main()

        ' If using the Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY")

        Dim document = DocumentModel.Load("%InputFileName%")

        ' Show line numbers on the right side of the page
        Dim pageSetup = document.Sections(0).PageSetup
        pageSetup.RightToLeft = true
        pageSetup.LineNumberRestartSetting = LineNumberRestartSetting.Continuous

        ' Create a new right-to-left paragraph
        Dim paragraph = new Paragraph(document)
        paragraph.ParagraphFormat.RightToLeft = true
        paragraph.Inlines.Add(new Run(document, "أخذ عن موالية الإمتعاض"))
        document.Sections(0).Blocks.Add(paragraph)

        ' Create a right-to-left table
        Dim table = new Table(document)
        table.TableFormat.RightToLeft = true
        table.TableFormat.PreferredWidth = new TableWidth(100, TableWidthUnit.Percentage)
        Dim row = new TableRow(document)
        table.Rows.Add(row)

        Dim firstCellPara = new Paragraph(document, "של תיבת תרומה מלא")
        firstCellPara.ParagraphFormat.RightToLeft = true
        row.Cells.Add(new TableCell(document, firstCellPara))

        Dim secondCellPara = new Paragraph(document, "200")
        row.Cells.Add(new TableCell(document, secondCellPara))

        document.Sections(0).Blocks.Add(table)

        document.Save("RightToLeft.%OutputFileType%")
    End Sub

End Module

See also


Next steps

GemBox.Document is a .NET component that enables you to read, write, edit, convert, and print document files from your .NET applications using one simple API. How about testing it today?

Download Buy