开发者

How to remove a column from an iTextSharp table

In my c# app, I have a function to generate a PDF document using iTextSharp, which includes a table of figures. The table (PdfPTable specifically) is populated and then inserted into the document. After it has been populated, under certain conditions, I would like t开发者_如何学JAVAo remove one of the columns - does anyone know how to do this?

I know I could conditionally exclude cells when populating the table, but this will be quite complex in my situation. Thanks


Because the tables in iTextSharp are generated a cell at a time I think it would be much easier to programmatically remove the 'column' at generation time rather than after it.


I would test for the condition, then include or not include the column when the table is being created.


You can adjust the column width to 0 so it does not appear by using the PdfPTable.SetWidths(float[])

For example

float[] ColumnWidths = new float[] { 10,0,10,0 };

PdfPTable table = new PdfPTable(ColumnWidths.Length);
table.SetWidths(ColumnWidths);

Now column 2 and 4 will no longer appear visually on the PDF, you can change the widths of the table at any point by passing a new float array to it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜