表单元格中的C#iText长段重叠

问题描述

我在C#上使用IText版本7。我正在将system.data.DataTable添加到iText.Layout.Element.Table。

我的挑战是,当单元格中的段落很长时,段落的第二行与第一行“重叠”。 我尝试将段落高度设置为12。但是仍然失败。我可以知道如何解决这个问题吗?

enter image description here

public void AddByTable(DataTable dbResult)
        {
            float[] columnWidths = { 25,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(),fontSize: 6));
                table.AddCell(_AddNewParagraph(row["RcvQty"].ToString(),fontSize: 6));
                table.AddCell(_AddNewParagraph(row["VAR"].ToString(),fontSize: 6));
            }

            _doc.Add(table);
        }

解决方法

您使用

.SetFixedLeading(2.0f)

确切要求您看到的行为。如果您不希望重叠的线,请不要将引线固定在太小的值。