我有一个主PdfpTable,其中一列用作父表。然后,我将用动态列创建的表添加到父表中。PdfpTable嵌套在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()设置了列的_relative_的宽度。所以如果你通过“50,100”,你不会传递50个单位和100个单位,而是说第一列应该得到三分之一(50 /(50 + 100)),第二列应该得到三分之二(100 /(50 + 100))'。相反,您可能希望使用'SetTotalWidth(float [])'以及'LockedWidth' –