'iText 7 - How to balance tables across multi columns?

I am using iText 7.2.1.

I need to add a table with a two-column style like the following. The table flows across two page columns and both side have headers.

enter image description here

I have read this official tutorial for multi columns: Chapter 3: Using renderers and event handlers | .NET

The problem is that, this 2-column renderer needs fixed column heights. So the two parts of the table are unbalanced.

Is there a way to make the table flow across two columns, and the height of each column is automatically balanced? (Which also means I don't need to know column heights when setting column widths)

And I also need to measure its height before it is rendered.

My Code:

using iText.IO.Font;
using iText.IO.Font.Constants;
using iText.Kernel.Colors;
using iText.Kernel.Font;
using iText.Kernel.Pdf;
using iText.Kernel.Pdf.Canvas;
using iText.Kernel.Geom;
using iText.Layout;
using iText.Layout.Borders;
using iText.Layout.Element;
using iText.Layout.Layout;
using iText.Layout.Renderer;

namespace iTextTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var writer = new PdfWriter("test.pdf");
            var pdfdoc = new PdfDocument(writer);
            var doc = new Document(pdfdoc);

            var table = new Table(4);
            for(int i = 0; i < 4; i++)
            {
                var cell = new Cell();
                cell.Add(new Paragraph("Header" + i.ToString()));
                table.AddHeaderCell(cell);
            }                
            for(int i = 0; i < 128; i++)
            {
                var cell = new Cell();
                cell.Add(new Paragraph("Cell" + i.ToString()));
                table.AddCell(cell);
            }

            iText.Kernel.Geom.Rectangle[] columns = new iText.Kernel.Geom.Rectangle[] {
                new iText.Kernel.Geom.Rectangle(30, 200, 200, 400),
                new iText.Kernel.Geom.Rectangle(300, 200, 200, 400)
            };
            doc.SetRenderer(new ColumnDocumentRenderer(doc, columns));
            doc.Add(table);
            doc.Close();
            pdfdoc.Close();
            writer.Close();

            MessageBox.Show("OK");
        }
    }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source