Created
April 15, 2019 07:42
-
-
Save dingosaurus/ef8d5cf142c538b35580949cd1f776e8 to your computer and use it in GitHub Desktop.
reportlab font
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
from reportlab.pdfbase import pdfmetrics | |
from reportlab.pdfbase.ttfonts import TTFont | |
FONT = os.path.join(settings.PROJECT_PATH, 'path/to/verah.ttf') | |
FONT_BOLD = os.path.join(settings.PROJECT_PATH, 'path/to/verahb.ttf') | |
FONT_NAME = "ticket_font" | |
FONT_BOLD_NAME = "ticket_font_bold" | |
FONT_FAMILY = "ticket_font_family" | |
pdfmetrics.registerFont(TTFont(FONT_BOLD_NAME, FONT_BOLD)) | |
pdfmetrics.registerFont(TTFont(FONT_NAME, FONT)) | |
pdfmetrics.registerFontFamily(FONT_FAMILY, normal=FONT_NAME, bold=FONT_BOLD_NAME) | |
# ... | |
c = canvas.Canvas(file_path, pagesize=A4) | |
c.setFont(FONT_NAME, 12) | |
c.setTitle(u"Název XYZ") | |
# SETUP P STYLE | |
styles = getSampleStyleSheet() | |
styles.add(ParagraphStyle( | |
name='NormalBlockText', | |
fontSize=11, | |
fontName=FONT_NAME, | |
# leading=13, | |
alignment=TA_JUSTIFY | |
)) | |
# ... | |
p = Paragraph(unicode(action.text_1) or "", styles["NormalBlockText"]) | |
w, h = p.wrap(180 * mm, 40 * mm) | |
p.drawOn(c, COL_1, 95 * mm - p.height) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment