Beispiel #1
0
 /**
  * Adds content to this object.
  * @param element
  * @throws BadElementException
  */
 public void AddElement(SimpleCell element)
 {
     if (!element.Cellgroup)
     {
         throw new BadElementException("You can't add cells to a table directly, add them to a row first.");
     }
     content.Add(element);
 }
Beispiel #2
0
        /**
         * Creates a Cell with these attributes.
         * @param rowAttributes
         * @return a cell based on these attributes.
         * @throws BadElementException
         */
        public Cell CreateCell(SimpleCell rowAttributes)
        {
            Cell cell = new Cell();

            cell.CloneNonPositionParameters(rowAttributes);
            cell.SoftCloneNonPositionParameters(this);
            cell.Colspan             = colspan;
            cell.HorizontalAlignment = horizontalAlignment;
            cell.VerticalAlignment   = verticalAlignment;
            cell.UseAscender         = useAscender;
            cell.UseBorderPadding    = useBorderPadding;
            cell.UseDescender        = useDescender;
            foreach (IElement element in content)
            {
                cell.AddElement(element);
            }
            return(cell);
        }
Beispiel #3
0
        /**
         * Creates a Table object based on this TableAttributes object.
         * @return a com.lowagie.text.Table object
         * @throws BadElementException
         */
        public Table CreateTable()
        {
            if (content.Count == 0)
            {
                throw new BadElementException("Trying to create a table without rows.");
            }
            SimpleCell rowx    = (SimpleCell)content[0];
            int        columns = 0;

            foreach (SimpleCell cell in rowx.Content)
            {
                columns += cell.Colspan;
            }
            float[] widths           = new float[columns];
            float[] widthpercentages = new float[columns];
            Table   table            = new Table(columns);

            table.Alignment = alignment;
            table.Spacing   = cellspacing;
            table.Padding   = cellpadding;
            table.CloneNonPositionParameters(this);
            int pos;

            foreach (SimpleCell row in content)
            {
                pos = 0;
                foreach (SimpleCell cell in row.Content)
                {
                    table.AddCell(cell.CreateCell(row));
                    if (cell.Colspan == 1)
                    {
                        if (cell.Width > 0)
                        {
                            widths[pos] = cell.Width;
                        }
                        if (cell.Widthpercentage > 0)
                        {
                            widthpercentages[pos] = cell.Widthpercentage;
                        }
                    }
                    pos += cell.Colspan;
                }
            }
            float sumWidths = 0f;

            for (int i = 0; i < columns; i++)
            {
                if (widths[i] == 0)
                {
                    sumWidths = 0;
                    break;
                }
                sumWidths += widths[i];
            }
            if (sumWidths > 0)
            {
                table.Width  = sumWidths;
                table.Locked = true;
                table.Widths = widths;
            }
            else
            {
                for (int i = 0; i < columns; i++)
                {
                    if (widthpercentages[i] == 0)
                    {
                        sumWidths = 0;
                        break;
                    }
                    sumWidths += widthpercentages[i];
                }
                if (sumWidths > 0)
                {
                    table.Widths = widthpercentages;
                }
            }
            if (width > 0)
            {
                table.Width  = width;
                table.Locked = true;
            }
            else if (widthpercentage > 0)
            {
                table.Width = widthpercentage;
            }
            return(table);
        }
Beispiel #4
0
        /**
         * Creates a PdfPTable object based on this TableAttributes object.
         * @return a com.lowagie.text.pdf.PdfPTable object
         * @throws DocumentException
         */
        public PdfPTable CreatePdfPTable()
        {
            if (content.Count == 0)
            {
                throw new BadElementException("Trying to create a table without rows.");
            }
            SimpleCell rowx    = (SimpleCell)content[0];
            int        columns = 0;

            foreach (SimpleCell cell in rowx.Content)
            {
                columns += cell.Colspan;
            }
            float[]   widths           = new float[columns];
            float[]   widthpercentages = new float[columns];
            PdfPTable table            = new PdfPTable(columns);

            table.TableEvent          = this;
            table.HorizontalAlignment = alignment;
            int pos;

            foreach (SimpleCell row in content)
            {
                pos = 0;
                foreach (SimpleCell cell in row.Content)
                {
                    if (float.IsNaN(cell.Spacing_left))
                    {
                        cell.Spacing_left = cellspacing / 2f;
                    }
                    if (float.IsNaN(cell.Spacing_right))
                    {
                        cell.Spacing_right = cellspacing / 2f;
                    }
                    if (float.IsNaN(cell.Spacing_top))
                    {
                        cell.Spacing_top = cellspacing / 2f;
                    }
                    if (float.IsNaN(cell.Spacing_bottom))
                    {
                        cell.Spacing_bottom = cellspacing / 2f;
                    }
                    cell.Padding = cellpadding;
                    table.AddCell(cell.CreatePdfPCell(row));
                    if (cell.Colspan == 1)
                    {
                        if (cell.Width > 0)
                        {
                            widths[pos] = cell.Width;
                        }
                        if (cell.Widthpercentage > 0)
                        {
                            widthpercentages[pos] = cell.Widthpercentage;
                        }
                    }
                    pos += cell.Colspan;
                }
            }
            float sumWidths = 0f;

            for (int i = 0; i < columns; i++)
            {
                if (widths[i] == 0)
                {
                    sumWidths = 0;
                    break;
                }
                sumWidths += widths[i];
            }
            if (sumWidths > 0)
            {
                table.TotalWidth = sumWidths;
                table.SetWidths(widths);
            }
            else
            {
                for (int i = 0; i < columns; i++)
                {
                    if (widthpercentages[i] == 0)
                    {
                        sumWidths = 0;
                        break;
                    }
                    sumWidths += widthpercentages[i];
                }
                if (sumWidths > 0)
                {
                    table.SetWidths(widthpercentages);
                }
            }
            if (width > 0)
            {
                table.TotalWidth = width;
            }
            if (widthpercentage > 0)
            {
                table.WidthPercentage = widthpercentage;
            }
            return(table);
        }
Beispiel #5
0
        /**
         * Creates a PdfPCell with these attributes.
         * @param rowAttributes
         * @return a PdfPCell based on these attributes.
         */
        public PdfPCell CreatePdfPCell(SimpleCell rowAttributes)
        {
            PdfPCell cell = new PdfPCell();

            cell.Border = NO_BORDER;
            SimpleCell tmp = new SimpleCell(CELL);

            tmp.Spacing_left   = spacing_left;
            tmp.Spacing_right  = spacing_right;
            tmp.Spacing_top    = spacing_top;
            tmp.Spacing_bottom = spacing_bottom;
            tmp.CloneNonPositionParameters(rowAttributes);
            tmp.SoftCloneNonPositionParameters(this);
            cell.CellEvent           = tmp;
            cell.HorizontalAlignment = rowAttributes.horizontalAlignment;
            cell.VerticalAlignment   = rowAttributes.verticalAlignment;
            cell.UseAscender         = rowAttributes.useAscender;
            cell.UseBorderPadding    = rowAttributes.useBorderPadding;
            cell.UseDescender        = rowAttributes.useDescender;
            cell.Colspan             = colspan;
            if (horizontalAlignment != Element.ALIGN_UNDEFINED)
            {
                cell.HorizontalAlignment = horizontalAlignment;
            }
            if (verticalAlignment != Element.ALIGN_UNDEFINED)
            {
                cell.VerticalAlignment = verticalAlignment;
            }
            if (useAscender)
            {
                cell.UseAscender = useAscender;
            }
            if (useBorderPadding)
            {
                cell.UseBorderPadding = useBorderPadding;
            }
            if (useDescender)
            {
                cell.UseDescender = useDescender;
            }
            float p;
            float sp_left = spacing_left;

            if (float.IsNaN(sp_left))
            {
                sp_left = 0f;
            }
            float sp_right = spacing_right;

            if (float.IsNaN(sp_right))
            {
                sp_right = 0f;
            }
            float sp_top = spacing_top;

            if (float.IsNaN(sp_top))
            {
                sp_top = 0f;
            }
            float sp_bottom = spacing_bottom;

            if (float.IsNaN(sp_bottom))
            {
                sp_bottom = 0f;
            }
            p = padding_left;
            if (float.IsNaN(p))
            {
                p = 0f;
            }
            cell.PaddingLeft = p + sp_left;
            p = padding_right;
            if (float.IsNaN(p))
            {
                p = 0f;
            }
            cell.PaddingRight = p + sp_right;
            p = padding_top;
            if (float.IsNaN(p))
            {
                p = 0f;
            }
            cell.PaddingTop = p + sp_top;
            p = padding_bottom;
            if (float.IsNaN(p))
            {
                p = 0f;
            }
            cell.PaddingBottom = p + sp_bottom;
            foreach (IElement element in content)
            {
                cell.AddElement(element);
            }
            return(cell);
        }