Last active
November 20, 2018 13:05
-
-
Save sottabyte/8da1d79fc5fdbc263da31c52cded6ff1 to your computer and use it in GitHub Desktop.
font and RTL in pdfkit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pdfkit | |
# https://pypi.org/project/pdfkit/ | |
# https://github.com/JazzCore/python-pdfkit/blob/master/travis/before-script.sh | |
m = "اوه، یه متن برای تست!" | |
# set font and rtl in html code | |
body = """ | |
<html> | |
<head> | |
<style> | |
p.rtl { | |
direction: rtl; | |
} | |
</style> | |
</head> | |
<p style="font-family:gandom;" class="rtl">%s</p></p> | |
</html> | |
""" % m | |
#size and encoding | |
options = { | |
'page-size': 'A4', | |
'margin-top': '0.75in', | |
'margin-right': '0.75in', | |
'margin-bottom': '0.75in', | |
'margin-left': '0.75in', | |
'encoding': "UTF-8", | |
'custom-header' : [ | |
('Accept-Encoding', 'gzip') | |
]} | |
#end | |
pdfkit.from_string(body,'out.pdf',options=options) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment