public virtual void CalculateColumnWidthsNotPointValue()
        {
            PdfDocument pdfDoc    = new PdfDocument(new PdfWriter(new ByteArrayOutputStream()));
            Document    doc       = new Document(pdfDoc);
            Rectangle   layoutBox = new Rectangle(0, 0, 1000, 100);
            Table       table     = new Table(UnitValue.CreatePercentArray(new float[] { 10, 10, 80 }));

            // Set margins and paddings in percents, which is not expected
            table.SetProperty(Property.MARGIN_RIGHT, UnitValue.CreatePercentValue(7));
            table.SetProperty(Property.MARGIN_LEFT, UnitValue.CreatePercentValue(7));
            table.SetProperty(Property.PADDING_RIGHT, UnitValue.CreatePercentValue(7));
            table.SetProperty(Property.PADDING_LEFT, UnitValue.CreatePercentValue(7));
            // Fill the table somehow. The layout area is wide enough to calculate the widths as expected
            for (int i = 0; i < 3; i++)
            {
                table.AddCell("Hello");
            }
            // Create a TableRenderer, the instance of which will be used to test the application of margins and paddings
            TableRenderer tableRenderer = (TableRenderer)table.CreateRendererSubTree().SetParent(doc.GetRenderer());

            tableRenderer.bordersHandler = (TableBorders) new SeparatedTableBorders(tableRenderer.rows, 3, tableRenderer
                                                                                    .GetBorders(), 0);
            tableRenderer.ApplyMarginsAndPaddingsAndCalculateColumnWidths(layoutBox);
            // Specify that the render is not original in order not to recalculate the column widths
            tableRenderer.isOriginalNonSplitRenderer = false;
            MinMaxWidth minMaxWidth = tableRenderer.GetMinMaxWidth();

            // TODO DEVSIX-3676: currently margins and paddings are still applied as if they are in points. After the mentioned ticket is fixed, the expected values should be updated.
            NUnit.Framework.Assert.AreEqual(minMaxWidth.GetMaxWidth(), 332.46f, 0.001);
            NUnit.Framework.Assert.AreEqual(minMaxWidth.GetMinWidth(), 332.46f, 0.001);
        }
Beispiel #2
0
        public virtual void HeaderFooterTableTest()
        {
            String   outFileName = destinationFolder + "headerFooterTableTest.pdf";
            String   cmpFileName = sourceFolder + "cmp_headerFooterTableTest.pdf";
            Document doc         = new Document(new PdfDocument(new PdfWriter(outFileName)));
            Cell     bigCell     = new Cell().Add(new Paragraph("veryveryveryvery big cell")).SetBorder(new SolidBorder(ColorConstants
                                                                                                                        .RED, 40)).SetBorderBottom(Border.NO_BORDER).SetBorderTop(Border.NO_BORDER).SetPadding(0);
            Cell mediumCell = new Cell().Add(new Paragraph("mediumsize cell")).SetBorder(new SolidBorder(ColorConstants
                                                                                                         .GREEN, 30)).SetBorderBottom(Border.NO_BORDER).SetBorderTop(Border.NO_BORDER).SetPadding(0);
            Cell cell = new Cell().Add(new Paragraph("cell")).SetBorder(new SolidBorder(ColorConstants.BLUE, 10)).SetBorderBottom
                            (Border.NO_BORDER).SetBorderTop(Border.NO_BORDER).SetPadding(0);
            Table table = new Table(UnitValue.CreatePercentArray(3)).UseAllAvailableWidth().SetBorder(new SolidBorder(
                                                                                                          ColorConstants.BLACK, 20)).AddCell(mediumCell.Clone(true)).AddCell(mediumCell.Clone(true)).AddCell(mediumCell
                                                                                                                                                                                                             .Clone(true)).AddFooterCell(cell.Clone(true)).AddFooterCell(cell.Clone(true)).AddFooterCell(bigCell.Clone
                                                                                                                                                                                                                                                                                                             (true)).AddHeaderCell(bigCell.Clone(true)).AddHeaderCell(cell.Clone(true)).AddHeaderCell(cell.Clone(true
                                                                                                                                                                                                                                                                                                                                                                                                                 ));
            TableRenderer renderer    = (TableRenderer)table.CreateRendererSubTree().SetParent(doc.GetRenderer());
            MinMaxWidth   minMaxWidth = renderer.GetMinMaxWidth();
            Table         minTable    = new Table(new float[] { -1, -1, -1 }).SetWidth(UnitValue.CreatePointValue(1)).SetBorder(new
                                                                                                                                SolidBorder(ColorConstants.BLACK, 20)).SetMarginTop(20).AddCell(mediumCell.Clone(true)).AddCell(mediumCell
                                                                                                                                                                                                                                .Clone(true)).AddCell(mediumCell.Clone(true)).AddFooterCell(cell.Clone(true)).AddFooterCell(cell.Clone
                                                                                                                                                                                                                                                                                                                                (true)).AddFooterCell(bigCell.Clone(true)).AddHeaderCell(bigCell.Clone(true)).AddHeaderCell(cell.Clone
                                                                                                                                                                                                                                                                                                                                                                                                                                (true)).AddHeaderCell(cell.Clone(true));
            Table maxTable = new Table(new float[] { -1, -1, -1 }).SetBorder(new SolidBorder(ColorConstants.BLACK, 20)
                                                                             ).SetMarginTop(20).AddCell(mediumCell.Clone(true)).AddCell(mediumCell.Clone(true)).AddCell(mediumCell.
                                                                                                                                                                        Clone(true)).AddFooterCell(cell.Clone(true)).AddFooterCell(cell.Clone(true)).AddFooterCell(bigCell.Clone
                                                                                                                                                                                                                                                                       (true)).AddHeaderCell(bigCell.Clone(true)).AddHeaderCell(cell.Clone(true)).AddHeaderCell(cell.Clone(true
                                                                                                                                                                                                                                                                                                                                                                           ));

            doc.Add(table);
            doc.Add(minTable);
            doc.Add(maxTable);
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }