【发布时间】:2016-05-31 14:12:46
【问题描述】:
我有一个主 PdfpTable,其中有一列用作父表。然后,我将使用动态列数创建的表添加到父表中。
所以每个表都是父表中的一行。 我得到了我想要的,除了几件事:
1) 表格在左右两边都添加了重要的空白;我希望子表填充行空间。
2) 列宽不成立。每个新表的第一列会根据其总列数更改宽度。
3) 主表宽度似乎不受 .TotalWidth 设置的影响
PdfPTable mainTable = new PdfPTable(1);
mainTable.TotalWidth = 1000f;
//Iterating through some data, get the count then create tables.
PdfPTable subTable = new PdfPTable(colCount);
//I tried setting the widths to fix issue 2
float[] colWidths = new float[colCount];
colWidths[0] = 50f;
for (int i = 1; i < colCount; i++)
{
colWidths[i] = 50f;
}
subTable.SetWidths(colWidths);
PdfPCell cell = new PdfPCell();
cell.AddElement("test");
subTable.AddCell(cell);
PdfPCell tblCell = new PdfPCell();
//tblCell.Padding = 0f;
//tblCell.PaddingLeft = 0f;
//tblCell.PaddingRight = 0f;
tblCell.AddElement(subTable);
mainTable.AddCell(tblCell);
我尝试设置每列的宽度,删除填充,并设置父表和子表的总宽度,但结果好坏参半。
【问题讨论】:
-
我没有时间给出完整的答案,但令人困惑的一点是
SetWidths()设置了列的相对 宽度。因此,如果您传递“50, 100”,您不是传递 50 个单位和 100 个单位,而是说第一列应该得到三分之一(50/(50+100)),第二列应该得到三分之二(100/(50+100))。相反,您可能想使用SetTotalWidth(float[])和LockedWidth
标签: c# itextsharp pdfptable