I've been trying to create a PDF file from content that can be English, Persian, digits or a combination of them.
there is some problems with Persian texts like: "این یک متن فارسی است"
۱- the text must be written from right to left
2- there is a difference between characters in different positions in the word (meaning that characters change their shape according to their surrounding characters)
3- because the sentence is read from right to left then the normal textwrap doesn't work correctly.
I used reportlab for creating PDf but unfortunately reportlab doesn't support Arabic and Persian alphabet so I used 'rtl' library by Vahid Mardani and 'pybidi' library by Meir Kriheli to make the text look right in PDF result.
first we need to add a font that supports Persian to reportlab:
in ubuntu 14.04:
add font and styles to reportlab:
in next step we need to reshape Persian text Letters to the right shape and make the direction of each word from right to left:
and for adding bullet or wrapping the text we could use following function:
for testing the code we can write: