Ejemplo n.º 1
0
        public virtual void TestProcessCellsWithPercentWidth02()
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(new MemoryStream()));
            Document    doc    = new Document(pdfDoc);
            Table       table  = new Table(UnitValue.CreatePercentArray(new float[] { 2, 1, 1 }));

            table.SetWidth(UnitValue.CreatePercentValue(80));
            table.SetHorizontalAlignment(HorizontalAlignment.CENTER);
            Cell c1 = new Cell(1, 3);

            c1.SetProperty(Property.WIDTH, UnitValue.CreatePercentValue(90));
            c1.Add(new Paragraph("Cell with colspan 3"));
            table.AddCell(c1);
            Cell c2 = new Cell(2, 1);

            c2.Add(new Paragraph("Cell with rowspan 2"));
            c2.SetProperty(Property.WIDTH, UnitValue.CreatePercentValue(50));
            table.AddCell(c2);
            table.AddCell(new Cell().Add(new Paragraph("row 1; cell 1")).SetMinWidth(200));
            table.AddCell(new Cell().Add(new Paragraph("row 1; cell 2")).SetMaxWidth(50));
            table.AddCell("row 2; cell 1");
            table.AddCell("row 2; cell 2");
            TableRenderer tableRenderer = new TableRenderer(table);

            CellRenderer[] row1 = new CellRenderer[] { new CellRenderer(table.GetCell(0, 0)), null, null };
            CellRenderer[] row2 = new CellRenderer[] { null, new CellRenderer(table.GetCell(1, 1)), new CellRenderer(table
                                                                                                                     .GetCell(1, 2)) };
            CellRenderer[] row3 = new CellRenderer[] { new CellRenderer(table.GetCell(1, 0)), new CellRenderer(table.GetCell
                                                                                                                   (2, 1)), new CellRenderer(table.GetCell(2, 2)) };
            tableRenderer.rows[0] = row1;
            tableRenderer.rows[1] = row2;
            tableRenderer.rows[2] = row3;
            table.SetBorder(new SolidBorder(ColorConstants.GREEN, 5));
            tableRenderer.bordersHandler = new SeparatedTableBorders(tableRenderer.rows, table.GetNumberOfColumns(), tableRenderer
                                                                     .GetBorders());
            TableWidths tableWidths            = new TableWidths(tableRenderer, 150, true, 15, 15);
            IList <TableWidths.CellInfo> cells = tableWidths.AutoLayoutCustom();

            foreach (TableWidths.CellInfo cell in cells)
            {
                tableWidths.ProcessCell(cell);
            }
            tableWidths.Recalculate(200);
            doc.Add(table);
            doc.Close();
        }
Ejemplo n.º 2
0
        public virtual void TestProcessCellsWithPercentWidth01()
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(new MemoryStream()));
            Document    doc    = new Document(pdfDoc);

            doc.Add(new Paragraph("With 2 columns:"));
            Table table = new Table(UnitValue.CreatePercentArray(2)).UseAllAvailableWidth();

            table.SetMarginTop(5);
            for (int i = 0; i < 4; i++)
            {
                Cell cell = new Cell().Add(new Paragraph("smth" + i));
                cell.SetProperty(Property.WIDTH, UnitValue.CreatePercentValue(50));
                table.AddCell(cell);
            }
            TableRenderer tableRenderer = new TableRenderer(table);

            CellRenderer[] row1 = new CellRenderer[] { new CellRenderer(table.GetCell(0, 0)), new CellRenderer(table.GetCell
                                                                                                                   (0, 1)) };
            CellRenderer[] row2 = new CellRenderer[] { new CellRenderer(table.GetCell(1, 0)), new CellRenderer(table.GetCell
                                                                                                                   (1, 1)) };
            tableRenderer.rows[0] = row1;
            tableRenderer.rows[1] = row2;
            table.SetBorder(new SolidBorder(ColorConstants.GREEN, 5));
            tableRenderer.bordersHandler = new SeparatedTableBorders(tableRenderer.rows, table.GetNumberOfColumns(), tableRenderer
                                                                     .GetBorders());
            TableWidths tableWidths            = new TableWidths(tableRenderer, 150, true, 15, 15);
            IList <TableWidths.CellInfo> cells = tableWidths.AutoLayoutCustom();

            foreach (TableWidths.CellInfo cell in cells)
            {
                tableWidths.ProcessCell(cell);
            }
            tableWidths.Recalculate(25);
            doc.Close();
        }