簡體   English   中英

Reportlab - 如何在單詞之間添加空格

[英]Reportlab - How to add space between words

我有一個文字:

elements.append(Paragraph(<font size=10>word1 word2</font>, styleSheet["Normal"]))

我想在word1和word2之間添加空格:

word1    word2

我怎么能這樣做?

我知道我在這方面有點晚了,但是為不間斷的空間添加了html &nbsp; 為我工作。

我懷疑它有一個簡單的解決方案。

作為一種解決方法,您可以嘗試在段落中添加空白(transperent或背景顏色)1px x 1px圖像並將其縮放到所需的寬度。

<font size=10>word1<img src="../path/to/image" width="10" />word2</font>

另一個(繁瑣)解決方案是使用canvas.beginText(x,y)創建的textobject來自己布局段落。

textobject = canvas.beginText(x, y)
textobject.setWordSpace(10)
textobject.textLine("word1 word2")
... (setting other parameters such as font etc.)
canvas.drawText(textobject)

希望這可以幫助。

def pad_text(text, num):
    text = str(text)
    num = int(num)
    text = text[:num]
    remaining = num - len(text)
    print(remaining)
    if (remaining == 0):
        return '<div>'+text+'</div>'
    else:
        res = '<div>'+text+ ' &nbsp;'*remaining +'</div>'
        return res

你可以用它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM