Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support RTL #593

Open
idobry opened this issue Apr 21, 2024 · 1 comment
Open

Support RTL #593

idobry opened this issue Apr 21, 2024 · 1 comment

Comments

@idobry
Copy link

idobry commented Apr 21, 2024

Hi chinapandaman
First and foremost, I want to thank you for this library, it is currently the most promising tool for what I'm trying to create.
I was able to load a custom Font, but the text is wrong.
The result should be בדיקה
but the text is הקידב
Here is my code:

    PdfWrapper.register_font("new_font_name", "/path/to/AharoniCLMBook.ttf")

    form = PdfWrapper("my-file.pdf", global_font="new_font_name")
    form.widgets["name_pensia_text_field_widget"].font = "new_font_name"

    form.fill(
            {
                "text_field_widget": 'בדיקה'
            },
    )
    with open("res.pdf", "wb+") as output:
        output.write(form.read())`
[aharoni-clm-book.zip](https://github.com/chinapandaman/PyPDFForm/files/15051733/aharoni-clm-book.zip)
@chinapandaman
Copy link
Owner

chinapandaman commented Apr 21, 2024

Hey, thanks for posting.

I traced through your snippet and up until this point text_to_draw was still בדיקה. But for some reason the canvas.drawString method (which is part of reportlab) seems to be drawing the characters in reverse order.

If I input the text in reverse order in the initial snippet, it will generate a correct PDF.

form.fill(
    {
        "text_field_widget": "הקידב"
    },
)

I also tried your code using the FormWrapper. Same thing, the final text is printed in reverse order. I'm not sure what language these characters are but I guess it's just a common thing that PDF, regardless directly drawn or input through text field, prints these characters in reverse order?

So the only thing I could tell you is if you are using this specific font, reverse the string first before feeding into the library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants