[英]How to add nested tables into existing table of PDF in iText using C#
The following code below gives me a table in iText. 下面的代码为我提供了iText中的表格。
However, I would like to also add two further columns to the right of the table; 但是,我还要在表格右侧添加另外两列; one which shows another '=' sign, (basically exactly the same as the 2nd column of the existing table) and then to the right of that I would like to add another column showing an 'a' (the same as the 1st column of the existing table).
一个显示另一个“ =”符号(基本上与现有表的第二列完全相同),然后在该符号的右侧添加另一个显示一个“ a”的列(与该表的第一列相同)现有表格)。
So really I want to take my existing table and add the 2nd and 1st column onto the end of it in that order so I finish with a table with 5 columns. 所以,实际上我想使用现有表并将第二列和第一列按此顺序添加到表的末尾,因此我要完成一个包含5列的表。 Do I need to produce a nested table for this?
我需要为此生成一个嵌套表吗? Any help would be much appreciated.
任何帮助将非常感激。
PdfPTable table0 = new PdfPTable(3);
float[] widths = new float[] { 7f, 0.5f, 4f };
table0.SetWidths(widths);
PdfPCell cell0 = new PdfPCell(new Phrase("a"));
cell0.Rowspan = 2;
cell0.VerticalAlignment = Element.ALIGN_MIDDLE;
cell0.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
table0.AddCell(cell0);
cell0 = new PdfPCell(new Phrase(" = "));
cell0.Rowspan = 2;
cell0.VerticalAlignment = Element.ALIGN_MIDDLE;
cell0.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
table0.AddCell(cell0);
cell0 = new PdfPCell(new Phrase("b"));
cell0.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
table0.AddCell(cell0);
cell0 = new PdfPCell(new Phrase("c"));
cell0.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
table0.AddCell(cell0);
document.Add(table0);
To "add the 2nd and 1st column onto the end of" your table, you need to: 要将“第二列和第一列添加到”表的末尾 ,您需要:
PdfPTable table0
for two more columns; PdfPTable table0
; float[] widths
to contain widths for two more columns; float[] widths
以包含另外两列的宽度; and Eg like this: 例如:
PdfPTable table0 = new PdfPTable(5);
float[] widths = new float[] { 7f, 0.5f, 4f, 0.5f, 7f };
table0.SetWidths(widths);
PdfPCell cell0 = new PdfPCell(new Phrase("a"));
cell0.Rowspan = 2;
cell0.VerticalAlignment = Element.ALIGN_MIDDLE;
cell0.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
table0.AddCell(cell0);
cell0 = new PdfPCell(new Phrase(" = "));
cell0.Rowspan = 2;
cell0.VerticalAlignment = Element.ALIGN_MIDDLE;
cell0.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
table0.AddCell(cell0);
cell0 = new PdfPCell(new Phrase("b"));
cell0.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
table0.AddCell(cell0);
cell0 = new PdfPCell(new Phrase(" = "));
cell0.Rowspan = 2;
cell0.VerticalAlignment = Element.ALIGN_MIDDLE;
cell0.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
table0.AddCell(cell0);
cell0 = new PdfPCell(new Phrase("a"));
cell0.Rowspan = 2;
cell0.VerticalAlignment = Element.ALIGN_MIDDLE;
cell0.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
table0.AddCell(cell0);
cell0 = new PdfPCell(new Phrase("c"));
cell0.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
table0.AddCell(cell0);
document.Add(table0);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.