简体   繁体   English

python自动换行和reportlab

[英]python wrap text and reportlab

I have a little code and I would like to wrap my long string in every 10th character and then add it into a PDF using reportlab: 我有一些代码,我想将长字符串用第10个字符包装,然后使用reportlab将其添加到PDF中:

This is how I try: 这是我尝试的方法:

text = '*long_text_long_text_long_text_long_text*'
text = "\n".join(wrap(text, 10))
canvas.drawString(5,227, text)

My pdf was created but where I want to break the lines I can only see black rectangles. 我的pdf已创建,但我想在其中折断的地方只能看到黑色矩形。 You can see the attached picture: 您可以看到所附图片:

在此处输入图片说明

Can you help me? 你能帮助我吗? Thank you! 谢谢!

drawString draws a single line. drawString绘制一条线。 so you will need to adjust the coordinate for each line in a loop. 因此您需要调整循环中每条线的坐标。

y = 227
for line in wrap(text, 10):
    canvas.drawString(5, y, line)
    y += 15

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM