table 单元格重叠中的 C# iText 长段落
C# iText long paragraph in table cell overlap
我在 C# 上使用 IText 版本 7。我正在将 system.data.DataTable 添加到 iText.Layout.Element.Table。
我的挑战是当单元格中的段落很长时,段落的第二行与第一行“重叠”。
我尝试将段落高度设置为 12。但它仍然失败。我可以知道如何解决这个问题吗?
public void AddByTable(DataTable dbResult)
{
float[] columnWidths = { 25, 3, 3, 3 };
Table table = new Table(UnitValue.CreatePercentArray(columnWidths)).UseAllAvailableWidth();
//add header
table.AddCell(_AddNewParagraph("Desc", padding: 1)) ;
table.AddCell(_AddNewParagraph("DO", padding: 1));
table.AddCell(_AddNewParagraph("Rec", padding: 1));
table.AddCell(_AddNewParagraph("Var", padding: 1));
table.SetKeepWithNext(true);
var strItemDesc="";
foreach (DataRow row in dbResult.Rows)
{
strItemDesc = row["vch_desc"].ToString();
//table.AddCell(_AddNewParagraph(strItemDesc, padding: 1,fontSize:6));
//table.AddCell(
// new Paragraph(strItemDesc)
// .SetFixedLeading(2.0f)
// .SetFont(_font)
// .SetFontSize(6)
// .SetPadding(1)
// );
Cell c= new Cell();
c.Add(
new Paragraph(strItemDesc)
.SetFixedLeading(2.0f)
.SetFont(_font)
.SetFontSize(6)
.SetPadding(1)
.SetHeight(12) //this height did no solve the overflow problem.
);
table.AddCell(c) ;
table.AddCell(_AddNewParagraph(row["DOQty"].ToString(), padding: 1, fontSize: 6));
table.AddCell(_AddNewParagraph(row["RcvQty"].ToString(), padding: 1, fontSize: 6));
table.AddCell(_AddNewParagraph(row["VAR"].ToString(), padding: 1, fontSize: 6));
}
_doc.Add(table);
}
您使用
.SetFixedLeading(2.0f)
它请求的正是您所看到的行为。如果您不想重叠线条,请不要将行距固定为太小的值。
我在 C# 上使用 IText 版本 7。我正在将 system.data.DataTable 添加到 iText.Layout.Element.Table。
我的挑战是当单元格中的段落很长时,段落的第二行与第一行“重叠”。 我尝试将段落高度设置为 12。但它仍然失败。我可以知道如何解决这个问题吗?
public void AddByTable(DataTable dbResult)
{
float[] columnWidths = { 25, 3, 3, 3 };
Table table = new Table(UnitValue.CreatePercentArray(columnWidths)).UseAllAvailableWidth();
//add header
table.AddCell(_AddNewParagraph("Desc", padding: 1)) ;
table.AddCell(_AddNewParagraph("DO", padding: 1));
table.AddCell(_AddNewParagraph("Rec", padding: 1));
table.AddCell(_AddNewParagraph("Var", padding: 1));
table.SetKeepWithNext(true);
var strItemDesc="";
foreach (DataRow row in dbResult.Rows)
{
strItemDesc = row["vch_desc"].ToString();
//table.AddCell(_AddNewParagraph(strItemDesc, padding: 1,fontSize:6));
//table.AddCell(
// new Paragraph(strItemDesc)
// .SetFixedLeading(2.0f)
// .SetFont(_font)
// .SetFontSize(6)
// .SetPadding(1)
// );
Cell c= new Cell();
c.Add(
new Paragraph(strItemDesc)
.SetFixedLeading(2.0f)
.SetFont(_font)
.SetFontSize(6)
.SetPadding(1)
.SetHeight(12) //this height did no solve the overflow problem.
);
table.AddCell(c) ;
table.AddCell(_AddNewParagraph(row["DOQty"].ToString(), padding: 1, fontSize: 6));
table.AddCell(_AddNewParagraph(row["RcvQty"].ToString(), padding: 1, fontSize: 6));
table.AddCell(_AddNewParagraph(row["VAR"].ToString(), padding: 1, fontSize: 6));
}
_doc.Add(table);
}
您使用
.SetFixedLeading(2.0f)
它请求的正是您所看到的行为。如果您不想重叠线条,请不要将行距固定为太小的值。