Reportlab polish signs

Reportlab polish signs
mail@pastecode.io avatar
unknown
python
2 years ago
1.2 kB
13
Indexable
Never
# imports for scripting
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas

# imports for fonts
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.pdfbase import pdfmetrics
pdfmetrics.registerFont(TTFont('Vera', 'Vera.ttf'))
pdfmetrics.registerFont(TTFont('Verdana', 'Verdana.ttf'))


# test font
font = 'Verdana'

def apply_scripting(textobject, text, rise):
    """Scripting method"""
    textobject.setFont(font , 8)
    textobject.setRise(rise)
    textobject.textOut(text)
    textobject.setFont(font , 12)
    textobject.setRise(0)


def main():
    canvas_obj = canvas.Canvas("textobj_rising.pdf",
                               pagesize=letter)
    # Create textobject
    textobject = canvas_obj.beginText()
    textobject.setFont(font , 12)
    # Set text location (x, y)
    textobject.setTextOrigin(10, 730)
    textobject.textOut('ReportLab ąłóćżźę')
    apply_scripting(textobject, 'superscript ąłóćżźę ', 7)

    textobject.textOut('and ')
    apply_scripting(textobject, 'subscript ąłóćżźę', -7)
    canvas_obj.drawText(textobject)
    canvas_obj.save()


if __name__ == '__main__':
    main()