我有一個主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' –