iTextSharp.text.Table.GetWidths C# (CSharp) Метод

GetWidths() публичный Метод

Gets an array with the positions of the borders between every column.
This method translates the widths expressed in percentages into the x-coordinate of the borders of the columns on a real document.
public GetWidths ( float left, float totalWidth ) : float[]
left float this is the position of the first border at the left (cellpadding not included)
totalWidth float /// this is the space between the first border at the left /// and the last border at the right (cellpadding not included) ///
Результат float[]
        public float[] GetWidths(float left, float totalWidth) {
            // for x columns, there are x+1 borders
            float[] w = new float[columns + 1];
            float wPercentage;
            if (locked) {
                wPercentage = 100 * width / totalWidth;
            }
            else {
                wPercentage = width;
            }
            // the border at the left is calculated
            switch (alignment) {
                case Element.ALIGN_LEFT:
                    w[0] = left;
                    break;
                case Element.ALIGN_RIGHT:
                    w[0] = left + (totalWidth * (100 - wPercentage)) / 100;
                    break;
                case Element.ALIGN_CENTER:
                default:
                    w[0] = left + (totalWidth * (100 - wPercentage)) / 200;
                    break;
            }
            // the total available width is changed
            totalWidth = (totalWidth * wPercentage) / 100;
            // the inner borders are calculated
            for (int i = 1; i < columns; i++) {
                w[i] = w[i - 1] + (widths[i - 1] * totalWidth / 100);
            }
            // the border at the right is calculated
            w[columns] = w[0] + totalWidth;
            return w;
        }

Usage Example

Пример #1
0
        // constructors
        /**
         * Constructs a <CODE>PdfTable</CODE>-object.
         *
         * @param   table   a <CODE>Table</CODE>
         * @param   left    the left border on the page
         * @param   right   the right border on the page
         * @param   top     the start position of the top of the table
         */
        internal PdfTable(Table table, float left, float right, float top, bool supportUpdateRowAdditions)
            : base(left, top, right, top)
        {
            // constructs a Rectangle (the bottomvalue will be changed afterwards)
            this.table = table;
            table.Complete();

            // copying the attributes from class Table
            CloneNonPositionParameters(table);

            this.columns = table.Columns;
            positions = table.GetWidths(left, right - left);

            // initialisation of some parameters
            Left = positions[0];
            Right = positions[positions.Length - 1];

            headercells = new ArrayList();
            cells = new ArrayList();

            UpdateRowAdditionsInternal();
            if (supportUpdateRowAdditions) {
                table.DeleteAllRows();
            }
        }