itextsharp - 减少 iTextSharp 上的段落换行高度

标签 itextsharp line-breaks paragraph

当段落长度对于 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/

相关文章:

html - 如果文本包含 '13' 和 '10',则显示换行符

html - 为什么在 bootstrap 中,当我最小化我的窗口时,我的 <p> 不断变长并将其下方的所有内容向下推

css - 文本在悬停时改变不透明度时闪烁

c# - 在 c#.net 中使用 iTextSharp 合并多个 PDF

c# - 通过 Response 发送内存中生成的 .PDF 文件

angularjs - 在 Angularjs 中显示文本之前设置文本格式

java - 如何在jtable中自动换行?

c# - 在 iTextSharp 中设置元数据

pdf - ITextSharp 添加文本。部分文字不显示

css - 使用 overflow hidden 的 <p> 的可见文本