Arabic text is written in reverse when filling PDF form and saving it

58 views
Skip to first unread message

Yousuf Yousuf

unread,
May 14, 2024, 11:09:08 AMMay 14
to Django users
I'm using fillpdf library to fill in a PDF form. When I use it externally it works fine and all.
When I save the file generated by fillpdf to my model the Arabic text becomes reversed.

Screenshot 2024-05-14 120336.png

This is my code:

import requests
        from fillpdf import fillpdfs
        from django.core.files import File, base
        from io import BytesIO
        from django.forms.models import model_to_dict

        ctx = {
            'full_name': 'منصور أحمد',
            'current_nationality': 'الإمارات العربية المتحدة'
        }

        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
        )

        with open("output.pdf", "wb") as f:
            f.write(out_stream.getbuffer())

        application.arabic_document.save("Some fillpdf file.pdf", base.ContentFile(out_stream.getbuffer()))
Reply all
Reply to author
Forward
0 new messages