【发布时间】:2021-03-18 16:02:09
【问题描述】:
如何使用IText 7 减少"Section 1" 和"Alert" 之间的行距?
这些是存储在数据库表中的值
<h3 style=color:#0000ff;><strong>Section 1</strong></h3>
<h4><strong>- Alert</strong></h4>
我尝试了这些链接但没有成功,因为不要更改 "Section 1" 和 "Alert" 之间的行距
- https://kb.itextpdf.com/home/it7kb/faq/how-to-change-the-line-spacing-of-text
- How to adjust spacing between paragraphs in iText7
下面是我的代码
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
contents = new Paragraph(dt.Rows[i]["contents"].ToString())
.SetTextAlignment(TextAlignment.JUSTIFIED)
.SetFontSize(12)
.SetMultipliedLeading(0.0f);
List<IElement> lst = HtmlConverter.ConvertToElements(dt.Rows[i]["contents"].ToString()).ToList();
for (int j = 0; j < lst.Count; j++)
{
IBlockElement element = (IBlockElement)lst[j];
if (dt.Rows[i]["contents"].ToString().StartsWith("<h3 style=color:#0000ff;><strong>Section"))
{
contents.SetFontSize(12)
.SetBold()
.SetFontColor(ColorConstants.BLUE)
.SetMultipliedLeading(0.0f);
}
else if (dt.Rows[i]["contents"].ToString().StartsWith("<h4><strong>- "))
{
contents.SetFontSize(10)
.SetBold()
.SetFontColor(ColorConstants.BLACK)
.SetMultipliedLeading(0.0f);
}
else
{
contents.SetFontSize(10)
.SetFontColor(ColorConstants.BLACK)
.SetMultipliedLeading(0.0f);
}
document.Add(element);
}
}
dest = filename.ToString();
}
【问题讨论】: