Bidirectional text is not displayed as expected

We’re struggling to control the behavior of bidirectional text within text form fields. Using “This is a test الشاشة الرئيس” as a test case the text order gets switched. Input and output files along with test code below.

@Test
public void setFieldValue() {
    final Document doc = new Document("./input.pdf");
    final Form form = doc.getForm();
    final String fieldName = "Text1";

    Arrays.stream(form.getFields())
        .filter(f -> f.getFullName().equals(fieldName))
        .forEach(tb -> {
        if (tb instanceof TextBoxField)

            {                 tb.setValue("This is a test الشاشة الرئيس");             }
    });
    doc.save("./output.pdf");
    doc.close();
}

input.pdf (11.3 KB)
output.pdf (88.1 KB)

@zhaolang

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFJAVA-42764

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.