Right-to-Left language issues: HorizontalAlignment.Right chops text

We just started using Aspose.pdf version 18.1 to work with right-to-left (RTL) languages, and there are a few things I’m having trouble getting to work correctly. First, the TextEditOptions.LanguageTransformation.Default setting appears to work, in general, for TextFragments. It doesn’t appear to do anything for HtmlFragments, however. Is this expected?

Second, what is the appropriate way to have RTL text appear flush up against the right margin of the page, instead of the left margin (as it would in English and LTR languages)? It doesn’t happen automatically with RTL text, and setting the HorizontalAlignment property to Right winds up chopping parts of letters off when a fragment is long enough to invoke line-wrapping. Specifically, it’s chopping some amount of space off of the right edge of each line except the last line. Here’s an image:
image.png (39.8 KB)

In that image, you can see that if the text is a single line, it looks fine if it’s aligned either left (incorrect for RTL) or right (correct for RTL). But when you extend the fragment so that it wraps, only the left-aligned (incorrect for RTL) text is preserved. The green box around the word الاختبار on the second line shows how this word should look. But if you look at the right-aligned version of this text, you can see (red box) that it’s had the rightmost part of the word chopped off. That same word on the last line of the fragment does not have its rightmost portion chopped off (green box). Playing with margins, padding, etc. does not affect this at all - the rightmost portion can still get chopped off.

Also, if you use the HorizontalAlignment.Justified setting, the RTL language transformation doesn’t seem to work (orange box). I’m not an Arabic speaker, but if you look at the order of the words in the Arabic-justified table cell, they aren’t in the right order compared to the other examples.

I’m sorry if this is long… can you please let me know the following?

  1. How to properly right-align RTL text without having parts of words chopped off when line-wrapping is invoked?
  2. If the HtmlFragment is expected to work with RTL?

I’m sorry – it looks like my image didn’t upload correctly – the colored boxes aren’t showing up – trying again:
Image.png (43.3 KB)

@bob.becker,

We have logged a feature request under the ticket ID PDFNET-44082 in our issue tracking system. We have linked your post to this ticket and will keep you informed regarding any available updates.

Kindly send the complete details of the scenario, including source documents and code. We will investigate and share our findings with you.

Thanks Imran,

I’m trying to use TextFragments with Arabic text. Since Arabic is read from right-to-left, I would like the text aligned with the right margin of the page, instead of the left margin – and the only way that I’ve found to do this is to set the HorizontalAlignment of the TextFragment to Right. This places the text in the correct place, but when the text in the fragment wraps to a new line, sometimes characters, or parts of characters, get chopped off on the right. This only happens if I use HorizontalAlignment=Right.

Here is the code that’s generating the PDF shown in the attached images, above:

        Document doc = new Document();

        Page page;

        MarginInfo marginInfo = new MarginInfo();
        marginInfo.Top = 90;
        marginInfo.Bottom = 90;
        marginInfo.Left = 50;
        marginInfo.Right = 50;

        page = doc.Pages.Add();
        page.PageInfo.Margin = marginInfo;

        // testing for letter-chopping
        string farsiString = " سلام این آزمون است";
        string arabicString = " مرحبا، هذا هو الاختبار";
        string hebrewString = " היי, זה מבחן";
        string mandarinString = "嗨,这是一个测试";
        string englishString = "Hi, this is a test ";

        Table table = new Table();
        table.DefaultCellBorder = new BorderInfo(BorderSide.All);
        table.DefaultCellPadding = new MarginInfo(0, 0, 0, 10);
        table.ColumnWidths = (page.PageInfo.Width * .2).ToString(CultureInfo.InvariantCulture) + " " + (page.PageInfo.Width * .8).ToString(CultureInfo.InvariantCulture);
        table.Margin = new MarginInfo(0, 10, 0, 10);

        Row row;
        Cell cell;
        TextFragment frag;

        row = new Row();
        cell = new Cell();
        frag = new TextFragment("Arabic - single line left");
        cell.Paragraphs.Add(frag);
        row.Cells.Add(cell);
        cell = new Cell();
        frag = new TextFragment(arabicString);
        frag.TextState.FontSize = 16;
        cell.Paragraphs.Add(frag);
        row.Cells.Add(cell);
        table.Rows.Add(row);

        row = new Row();
        cell = new Cell();
        frag = new TextFragment("Arabic - single line right");
        cell.Paragraphs.Add(frag);
        row.Cells.Add(cell);
        cell = new Cell();
        frag = new TextFragment(arabicString);
        frag.HorizontalAlignment = HorizontalAlignment.Right;
        frag.TextState.FontSize = 16;
        cell.Paragraphs.Add(frag);
        row.Cells.Add(cell);
        table.Rows.Add(row);

        row = new Row();
        cell = new Cell();
        frag = new TextFragment("Arabic - multi line left");
        cell.Paragraphs.Add(frag);
        row.Cells.Add(cell);
        cell = new Cell();
        frag = new TextFragment(arabicString + arabicString + arabicString + arabicString + arabicString + arabicString + arabicString + arabicString);
        frag.TextState.FontSize = 16;
        cell.Paragraphs.Add(frag);
        row.Cells.Add(cell);
        table.Rows.Add(row);

        row = new Row();
        cell = new Cell();
        frag = new TextFragment("Arabic - multi line right");
        cell.Paragraphs.Add(frag);
        row.Cells.Add(cell);
        cell = new Cell();
        frag = new TextFragment(arabicString + arabicString + arabicString + arabicString + arabicString + arabicString + arabicString + arabicString);
        frag.TextState.FontSize = 16;
        frag.HorizontalAlignment = HorizontalAlignment.Right;
        cell.Paragraphs.Add(frag);
        row.Cells.Add(cell);
        table.Rows.Add(row);

        row = new Row();
        cell = new Cell();
        frag = new TextFragment("Arabic - justified");
        cell.Paragraphs.Add(frag);
        row.Cells.Add(cell);
        cell = new Cell();
        frag = new TextFragment(arabicString + arabicString + arabicString + arabicString + arabicString + arabicString + arabicString + arabicString);
        frag.TextState.FontSize = 16;
        frag.HorizontalAlignment = HorizontalAlignment.Justify;
        cell.Paragraphs.Add(frag);
        row.Cells.Add(cell);
        table.Rows.Add(row);

        page.Paragraphs.Add(table);

        MemoryStream ms = new MemoryStream();
        doc.Save(ms);

        return ms.ToArray();

@bob.becker,

We managed to replicate the problem of chopped characters in the Arabic language rendering. It has been logged under the ticket ID PDFNET-44088 in our bug tracking system. We have linked your post to this ticket and will keep you informed regarding any available updates.

Just wanted to follow up and see if this has been addressed in any of the releases between 18.1 and 18.7. If not, are there any estimates of when this item (PDF-44088) will be addressed?

@bob.becker

Thank you for getting back to us.

We are afraid that the issue reported by you, PDFNET-44088, is still pending owing to previously logged tickets. We have raised its priority to next level and will share the ETA with you as soon as it will be investigated. We appreciate your patience and comprehension in this regard.