当段落长度对于 ColumnText 的宽度来说太长时,如何减少换行符的高度?
我已经尝试了以下方法,因为我看到了其他回答这个问题的问题:
p.Leading = 0
但这并没有产生任何影响。
我还尝试将
Leading
增加到 100
以查看是否添加了更大的换行符,但都不起作用。SpacingBefore/SpacingAfter 也无济于事:
p.SpacingBefore = 0
p.SpacingAfter = 0
我怎样才能减少这种情况?
最佳答案
使用表格时,您需要在单元格本身上设置行距。但是,您会看到 Leading
属性是只读的,因此您需要使用 SetLeading()
方法,该方法采用两个值,第一个是固定行距,第二个是乘法行距。根据 to this post here :
Multiplied basically means, the larger the font, the larger the leading. Fixed means the same leading for any font size.
要将前导缩小到 80%,您可以使用:
Dim P1 As New Paragraph("It was the best of times, it was the worst of times")
Dim C1 As New PdfPCell(P1)
C1.SetLeading(0, 0.8)
编辑
对不起,我看到了“专栏”,我缺乏咖啡的大脑去了 table 。
对于
ColumnText
,您应该能够很好地使用段落的前导值。Dim cb = writer.DirectContent
Dim ct As New ColumnText(cb)
ct.SetSimpleColumn(0, 0, 200, 200)
Dim P1 As New Paragraph("It was the best of times, it was the worst of times")
''//Disable fixed leading
P1.Leading = 0
''//Set a font-relative leading
P1.MultipliedLeading = 0.8
ct.AddElement(P1)
ct.Go()
在我运行 iTextSharp 5.1.2.0 的机器上,这会生成两行稍微挤压在一起的文本。
关于itextsharp - 减少 iTextSharp 上的段落换行高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9094461/