javaflying-sauceropenpdf

Flying Saucer: Arabic text in the footer of generated PDF is positioned incorrectly


I am using Flying Saucer to generate PDF in my project for long time already. My documents have header and footer repeated on each page. Everything is working fine.

Now I got a requirement to add support of arabic texts in the documents. I embedded the font with Arabic characters and implemented RTLTextReplacedElementFactory (copied from flying saucer support group). Arabic text is displayed OK while it is in a page. If arabic text is inside of the footer, then it is positioned incorrectly:

enter image description here

The footer is created using the following CSS:

        @page {
        @bottom-left {
            content: element(footer);
            vertical-align: top;
            border-top: 1px solid black;
        }

        size: A4 portrait;
        margin: 2cm;
    }

    html,
    body {
        font-family: 'Roboto', sans-serif;
        font-size: 12pt;
    }

    .arabic {
        font-family: "Noto Sans Arabic", sans-serif;
        font-size: 10pt;
        font-style: normal;
        font-weight: 100;
    }

    div#footer {
        display: block;
        position: running(footer);
    }

I do not understand why the arabic text is incorrectly positioned and I do not understand where to start debugging (also, if it possible to have arabic texts in the running footer at all).

The example project is here https://github.com/igorbljahhin/flying-saucer-issue-with-arabic-in-footer.

The issue is reproduced with iText5 and with OpenPDF.


Solution

  • I think RTLText.java:222 should be:

    float dist = box.getAbsY(); //from box top to page bottom
    

    I think that the bottom left corner of the page is the origin (0,0), X increases from left to right and Y increases from bottom to top. If box.getAbsY() gives you the Y coordinate of the top of the box, it is should be exactly the distance "from box top to page bottom".