减少iTextSharp上的段落线高度 [英] Reduce paragraph line break height on iTextSharp

查看:93
本文介绍了减少iTextSharp上的段落线高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果段落长度对于ColumnText的宽度太长,我怎样才能减少换行符的高度?

How can I reduce the height of a line break which occurs when a paragraph length is too long for the width of the ColumnText?

我试过以下,我已经看到其他问题回答了这个问题:

I've tried the following, as I've seen other questions which answered with this:

p.Leading = 0

但这没有任何影响。

我也试过增加领先 100 以查看是否添加了更大的换行符,但都没有工作。

I've also tried increasing the Leading to 100 to see if a larger line break is added, but neither work.

SpacingBefore / SpacingAfter也没有帮助:

SpacingBefore/SpacingAfter doesn't help either:

p.SpacingBefore = 0
p.SpacingAfter = 0

如何减少这个?

推荐答案

使用表时,需要在单元格本身上设置前导。但是,您会看到 Leading 属性是只读的,因此您需要使用 SetLeading()取两个值的方法,第一个是固定前导,第二个是乘以前导。根据这里的帖子

When using a table, you need to set the leading on the cell itself. However, you'll see that the Leading property is read-only so instead you'll need to use the SetLeading() method which takes two values, the first is the fixed leading and the second is the multiplied leading. According 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%,您将使用:

To shrink the leading to 80% you'd use:

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)

EDIT

对不起,我看到了专栏,而我缺乏咖啡的大脑也进了桌子。

Sorry, I saw "Column" and my coffee-lacking brain went to tables.

一个 ColumnText 你应该能够正确使用段落的前导值。

For a ColumnText you should be able to use the Paragraph's leading values just fine.

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()

在运行iTextShar的机器上p 5.1.2.0这会产生两行文字略微挤压在一起。

On my machine running iTextSharp 5.1.2.0 this produces two lines of text that are slightly squished together.

这篇关于减少iTextSharp上的段落线高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆