iTextSharp.text.pdf.PdfDocument.GetVerticalPosition C# (CSharp) Метод

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

public GetVerticalPosition ( bool ensureNewLine ) : float
ensureNewLine bool
Результат float
        public float GetVerticalPosition(bool ensureNewLine)
        {
            // ensuring that a new line has been started.
            if (ensureNewLine) {
                EnsureNewLine();
            }
            return Top - currentHeight - indentation.indentTop;
        }

Usage Example

Пример #1
0
        /**
        * Write out the columns.  After writing, use
        * {@link #isOverflow()} to see if all text was written.
        * @param canvas PdfContentByte to write with
        * @param document document to write to (only used to get page limit info)
        * @param documentY starting y position to begin writing at
        * @return the current height (y position) after writing the columns
        * @throws DocumentException on error
        */
        public float Write(PdfContentByte canvas, PdfDocument document, float documentY)
        {
            this.document = document;
            columnText.Canvas = canvas;
            if (columnDefs.Count == 0) {
                throw new DocumentException(MessageLocalization.GetComposedMessage("multicolumntext.has.no.columns"));
            }
            overflow = false;
            float currentHeight = 0;
            bool done = false;
            while (!done) {
                if (top == AUTOMATIC) {
                    top = document.GetVerticalPosition(true);
                }
                else if (nextY == AUTOMATIC) {
                    nextY = document.GetVerticalPosition(true); // RS - 07/07/2005 - - Get current doc writing position for top of columns on new page.
                }

                ColumnDef currentDef = columnDefs[CurrentColumn];
                columnText.YLine = top;

                float[] left = currentDef.ResolvePositions(Rectangle.LEFT_BORDER);
                float[] right = currentDef.ResolvePositions(Rectangle.RIGHT_BORDER);
                if (document.IsMarginMirroring() && document.PageNumber % 2 == 0){
                    float delta = document.RightMargin - document.Left;
                    left = (float[])left.Clone();
                    right = (float[])right.Clone();
                    for (int i = 0; i < left.Length; i += 2) {
                        left[i] -= delta;
                    }
                    for (int i = 0; i < right.Length; i += 2) {
                        right[i] -= delta;
                    }
                }
                currentHeight = Math.Max(currentHeight, GetHeight(left, right));

                if (currentDef.IsSimple()) {
                    columnText.SetSimpleColumn(left[2], left[3], right[0], right[1]);
                } else {
                    columnText.SetColumns(left, right);
                }

                int result = columnText.Go();
                if ((result & ColumnText.NO_MORE_TEXT) != 0) {
                    done = true;
                    top = columnText.YLine;
                } else if (ShiftCurrentColumn()) {
                    top = nextY;
                } else {  // check if we are done because of height
                    totalHeight += currentHeight;

                    if ((desiredHeight != AUTOMATIC) && (totalHeight >= desiredHeight)) {
                        overflow = true;
                        break;
                    } else {  // need to start new page and reset the columns
                        documentY = nextY;
                        NewPage();
                        currentHeight = 0;
                    }
                }
            }
            if (desiredHeight == AUTOMATIC && columnDefs.Count == 1) {
                currentHeight = documentY - columnText.YLine;
            }
            return currentHeight;
        }