1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| import textwrap
def draw_wrapped_line(canvas, text, length, x_pos, y_pos, y_offset):
"""
:param canvas: reportlab canvas
:param text: the raw text to wrap
:param length: the max number of characters per line
:param x_pos: starting x position
:param y_pos: starting y position
:param y_offset: the amount of space to leave between wrapped lines
"""
if len(text) > length:
wraps = textwrap.wrap(text, length)
for x in range(len(wraps)):
canvas.drawCenteredString(x_pos, y_pos, wraps[x])
y_pos -= y_offset
y_pos += y_offset # add back offset after last wrapped line
else:
canvas.drawCenteredString(x_pos, y_pos, text)
return y_pos |
Partager