简体   繁体   English

如何使用C#将嵌套表添加到iText中PDF的现有表中

[英]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: 要将“第二列和第一列添加到”的末尾 ,您需要:

  • initialize the PdfPTable table0 for two more columns; 为另外两列初始化PdfPTable table0
  • extend the float[] widths to contain widths for two more columns; 扩展float[] widths以包含另外两列的宽度; and
  • add the cells for two more columns. 为另外两列添加单元格。

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.

相关问题 如何在C#中使用itext7将u3d添加到现有的pdf中 - How to add u3d into existing pdf using itext7 with C# 如何在 C# 中使用 IText7 在现有 pdf 顶部添加条形码? - How to add a Barcode at the top of an existing pdf using IText7 in C#? 如何在c#中使用iText 7将SVG图形添加​​到pdf文档? - how to add SVG graphic to pdf document using iText 7 in c#? 如何在不使用 iText7 和 C# 覆盖内容的情况下向现有 pdf 添加文本? - How to add text to an existing pdf without overwriting the content with iText7 and C#? 如何使用IText7和C#在现有PDF中为内部链接加下划线? - How do I underline internal links in an existing PDF using IText7 and C#? 使用 iText7 C# 将 Javascript 添加到 PDF 文件 - Add Javascript to PDF file using iText7 C# 使用iText 7和C#将标题添加为可访问的pdf中的H1 - Add titles as H1 in accessible pdf using iText 7 and C# 如何在C#中使用iText将标头添加到PDF文件? - How can I add a header to a PDF file using iText in C#? 如何在 unity c# 中使用 itext7 将图像添加到 pdf? - How do I add image to pdf using itext7 in unity c#? 如何修改现有 PDF 中的外部链接,使其指向使用 IText7 和 C# 的文档中的内部页面? - How do I modify external link in an existing PDF such that it points to an internal page within document using IText7 and C#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM