コード例 #1
0
ファイル: PdfWriter.cs プロジェクト: pixelia-es/RazorPDF2
 /**
 * Use this method to get an instance of the <CODE>PdfWriter</CODE>.
 *
 * @return a new <CODE>PdfWriter</CODE>
 * @param document The <CODE>Document</CODE> that has to be written
 * @param os The <CODE>Stream</CODE> the writer has to write to.
 * @param listener A <CODE>DocListener</CODE> to pass to the PdfDocument.
 * @throws DocumentException on error
 */
 public static PdfWriter GetInstance(Document document, Stream os, IDocListener listener)
 {
     PdfDocument pdf = new PdfDocument();
     pdf.AddDocListener(listener);
     document.AddDocListener(pdf);
     PdfWriter writer = new PdfWriter(pdf, os);
     pdf.AddWriter(writer);
     return writer;
 }
コード例 #2
0
ファイル: PdfWriter.cs プロジェクト: pixelia-es/RazorPDF2
 /**
 * Constructs a <CODE>PdfWriter</CODE>.
 * <P>
 * Remark: a PdfWriter can only be constructed by calling the method
 * <CODE>getInstance(Document document, Stream os)</CODE>.
 *
 * @param    document    The <CODE>PdfDocument</CODE> that has to be written
 * @param    os          The <CODE>Stream</CODE> the writer has to write to.
 */
 protected PdfWriter(PdfDocument document, Stream os)
     : base(document, os)
 {
     root = new PdfPages(this);
     pdf = document;
     directContent = new PdfContentByte(this);
     directContentUnder = new PdfContentByte(this);
 }
コード例 #3
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("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 = (ColumnDef) 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;
        }