Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from reportlab.pdfbase.pdfmetrics import stringWidth
- from reportlab.pdfgen import canvas
- from reportlab.lib.units import mm
- c = canvas.Canvas('test.pdf', (195*mm, 50*mm))
- textobj = c.beginText()
- def width(string, font, size, charspace):
- width = stringWidth(string, font, size)
- width += (len(string) - 1) * charspace
- return width
- textobj.setFont('Times-Roman', 12)
- textobj.setTextOrigin((100*mm - width("Some string", 'Times-Roman', 12, 3)) / 2, 5*mm)
- textobj.setCharSpace(3)
- textobj.textLine("Some string")
- c.drawText(textobj)
- c.rect(0*mm, 5*mm, 100*mm, 10*mm)
- textobj.setFont('Times-Roman', 15)
- textobj.setTextOrigin((100*mm - width("Some longer string", 'Times-Roman', 15, 7)) / 2, 25*mm)
- textobj.setCharSpace(7)
- textobj.textLine("Some longer string")
- c.drawText(textobj)
- c.rect(0*mm, 25*mm, 100*mm, 10*mm)
- c.showPage()
- c.save()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement