Skip to content

Instantly share code, notes, and snippets.

@sottabyte
Last active November 20, 2018 13:05
Show Gist options
  • Save sottabyte/8da1d79fc5fdbc263da31c52cded6ff1 to your computer and use it in GitHub Desktop.
Save sottabyte/8da1d79fc5fdbc263da31c52cded6ff1 to your computer and use it in GitHub Desktop.
font and RTL in pdfkit
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