gpt4 book ai didi

python - 如何使用 Reportlab 在单个段落中的行之间添加空格

转载 作者:太空宇宙 更新时间:2023-11-03 12:29:20 26 4
gpt4 key购买 nike

我有一段文本,它是从数据库中动态提取的,并在提供给用户之前放置在 PDF 中。文本被放置在带衬里的背景上,很像记事本纸。我想间隔文本,以便每个背景行之间只有一行文本。

我能够使用以下代码在段落之间创建垂直间距(用于生成 PDF 的另一部分)。

    style = getSampleStyleSheet()['Normal']
style.fontName = 'Helvetica'
style.spaceAfter = 15
style.alignment = TA_JUSTIFY

story = [Paragraph(choice.value,style) for choice in chain(context['question1'].itervalues(),context['question2'].itervalues())]
generated_file = StringIO()
frame1 = Frame(50,100,245,240, showBoundary=0)
frame2 = Frame(320,100,245,240, showBoundary=0)
page_template = PageTemplate(frames=[frame1,frame2])
doc = BaseDocTemplate(generated_file,pageTemplates=[page_template])
doc.build(story)

但是,这在这里不起作用,因为我只有一个大段落。

最佳答案

很确定你想改变的是领导。来自第 6 章的用户手册。

To get double-spaced text, use a high leading. If you set autoLeading(default "off") to "min"(use observed leading even if smaller than specified) or "max"(use the larger of observed and specified) then an attempt is made to determine the leading on a line by line basis. This may be useful if the lines contain different font sizes etc.

领先在第 2 章的前面定义:

Interline spacing (Leading)

The vertical offset between the point at which one line starts and where the next starts is called the leading offset.

所以尝试不同的leading值,例如:

style = getSampleStyleSheet()['Normal']
style.leading = 24

关于python - 如何使用 Reportlab 在单个段落中的行之间添加空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5709907/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com