减少 iTextSharp 上的段落换行高度
当段落长度对于 ColumnText 的宽度来说太长时,如何减少换行符的高度?
我已经尝试了以下操作,因为我看到了其他回答此问题的问题:
p.Leading = 0
但这没有产生任何影响。
我还尝试将 Leading
增加到 100
以查看是否添加了更大的换行符,但这两种方法都不起作用。
SpacingBefore/SpacingAfter 也没有帮助:
p.SpacingBefore = 0
p.SpacingAfter = 0
我怎样才能减少这个?
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
But this has made no affect.
I've also tried increasing the Leading
to 100
to see if a larger line break is added, but neither work.
SpacingBefore/SpacingAfter doesn't help either:
p.SpacingBefore = 0
p.SpacingAfter = 0
How can I reduce this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用表格时,您需要设置单元格本身的行距。但是,您会看到
Leading
属性是只读的,因此您需要使用SetLeading()
方法,该方法接受两个值,第一个是固定前导,第二个是乘法前导。根据此处的这篇文章:要将行距缩小到 80%,您可以使用:
编辑
抱歉,我看到“Column”,我的咖啡缺乏大脑去了桌子。
对于
ColumnText
,您应该能够很好地使用段落的前导值。在我运行 iTextSharp 5.1.2.0 的机器上,这会生成两行稍微挤压在一起的文本。
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 theSetLeading()
method which takes two values, the first is the fixed leading and the second is the multiplied leading. According to this post here:To shrink the leading to 80% you'd use:
EDIT
Sorry, I saw "Column" and my coffee-lacking brain went to tables.
For a
ColumnText
you should be able to use the Paragraph's leading values just fine.On my machine running iTextSharp 5.1.2.0 this produces two lines of text that are slightly squished together.
好吧,您似乎偶然发现了文本模式和复合模式之间的区别:
当您处于文本模式时,可以通过设置
在“段落”之间添加空格>ColumnText
属性。当您处于复合模式时,您可以像平常一样在“容器”对象之间添加空格 - 即不使用
ColumnText
时的情况。下面是一个示例,展示了两种模式之间的差异::
现在您已经更新了代码,并使用了带有
AddElement()
、p.SpacingAfter = 0
的复合模式> 将删除段落之间的间距。或者将其设置为您想要的任何内容,而不是Paragraph.Leading
。Well it seems you've stumbled upon the difference between text mode and composite mode:
ColumnText.AddText()
using the "inline" Chunk and Phrase objects.ColumnText.AddText()
using "container" objects like Paragraph, Image, etcWhen you're in text mode, you add space between "paragraphs" by setting
ColumnText
properties.When you're in composite mode, you add space between "container" objects as you normally would - i.e. as you would if not using
ColumnText
.Here's an example to show the difference between the two modes::
So now that you've updated your code and are using composite mode with
AddElement()
,p.SpacingAfter = 0
WILL remove spacing between paragraphs. Or set it to whatever you want instead ofParagraph.Leading
.