t-houssian / fillpdf

A python library to make filling pdfs much easier
MIT License
134 stars 23 forks source link

Arabic text is written in reverse when used in Django #56

Closed Usouf closed 5 months ago

Usouf commented 6 months ago

When I use the library as a standalone it works fine and all. But when I use it in Django, it saves weirdly.

The standalone one: Screenshot 2024-05-14 093552

The Django one: Screenshot 2024-05-14 093611

This is my code:

def _fill_form(self, application):
        import requests
        from fillpdf import fillpdfs
        from django.core.files import File
        from io import BytesIO
        from django.forms.models import model_to_dict

        ctx = model_to_dict(application)

        response = requests.get("http://localhost:8000/static/document/form.pdf")
        if not response.ok:
            log.error("couldn't get form")

        in_stream = BytesIO(response.content)
        out_stream = BytesIO()

        fillpdfs.write_fillable_pdf(
            in_stream,
            out_stream,
            ctx,
            flatten=True
        )

        application.arabic_document.save("Some fillpdf file.pdf", File(out_stream))
Usouf commented 5 months ago

the issue was caused by the browser I was opening the pdf from. If you install a plugin that renders Arabic text it should work fine.