⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pdfcell.java

📁 一个java操作pdf文件的开发包,很好用的.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * $Id: PdfCell.java,v 1.55 2002/11/19 08:33:35 blowagie Exp $ * $Name:  $ * * Copyright 1999, 2000, 2001, 2002 Bruno Lowagie * * The contents of this file are subject to the Mozilla Public License Version 1.1 * (the "License"); you may not use this file except in compliance with the License. * You may obtain a copy of the License at http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the License. * * The Original Code is 'iText, a free JAVA-PDF library'. * * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie. * All Rights Reserved. * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved. * * Contributor(s): all the names of the contributors are added in the source code * where applicable. * * Alternatively, the contents of this file may be used under the terms of the * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the * provisions of LGPL are applicable instead of those above.  If you wish to * allow use of your version of this file only under the terms of the LGPL * License and not to allow others to use your version of this file under * the MPL, indicate your decision by deleting the provisions above and * replace them with the notice and other provisions required by the LGPL. * If you do not delete the provisions above, a recipient may use your version * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE. * * This library is free software; you can redistribute it and/or modify it * under the terms of the MPL as stated above or under the terms of the GNU * Library General Public License as published by the Free Software Foundation; * either version 2 of the License, or any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more * details. * * If you didn't download this code from the following link, you should check if * you aren't using an obsolete version: * http://www.lowagie.com/iText/ */package com.lowagie.text.pdf;import java.util.ArrayList;import java.util.Iterator;import com.lowagie.text.*;/** * A <CODE>PdfCell</CODE> is the PDF translation of a <CODE>Cell</CODE>. * <P> * A <CODE>PdfCell</CODE> is an <CODE>ArrayList</CODE> of <CODE>PdfLine</CODE>s. * * @see		com.lowagie.text.Rectangle * @see		com.lowagie.text.Cell * @see		PdfLine * @see		PdfTable */public class PdfCell extends Rectangle {        // membervariables        /** These are the PdfLines in the Cell. */    private ArrayList lines;        /** These are the PdfLines in the Cell. */    private PdfLine line;        /** These are the Images in the Cell. */    private ArrayList images;        /** This is the leading of the lines. */    private float leading;        /** This is the number of the row the cell is in. */    private int rownumber;        /** This is the rowspan of the cell. */    private int rowspan;        /** This is the cellspacing of the cell. */    private float cellspacing;        /** This is the cellpadding of the cell. */    private float cellpadding;        /** Indicates if this cell belongs to the header of a <CODE>PdfTable</CODE> */    private boolean header = false;            // constructors        /**     * Constructs a <CODE>PdfCell</CODE>-object.     *     * @param	cell		the original <CODE>Cell</CODE>     * @param	rownumber	the number of the <CODE>Row</CODE> the <CODE>Cell</CODE> was in.     * @param	left		the left border of the <CODE>PdfCell</CODE>     * @param	right		the right border of the <CODE>PdfCell</CODE>     * @param	top			the top border of the <CODE>PdfCell</CODE>     * @param	cellspacing	the cellspacing of the <CODE>Table</CODE>     * @param	cellpadding	the cellpadding	of the <CODE>Table</CODE>     */        public PdfCell(Cell cell, int rownumber, float left, float right, float top, float cellspacing, float cellpadding) {        // constructs a Rectangle (the bottomvalue will be changed afterwards)        super(left, top, right, top);        // copying the attributes from class Cell        setBorder(cell.border());        setBorderWidth(cell.borderWidth());        setBorderColor(cell.borderColor());        setBackgroundColor(cell.backgroundColor());        setGrayFill(cell.grayFill());                // initialisation of some parameters        PdfChunk chunk;        Element element;        PdfChunk overflow;        lines = new ArrayList();        images = new ArrayList();        leading = cell.leading();        int alignment = cell.horizontalAlignment();        left += cellspacing + cellpadding;        right -= cellspacing + cellpadding;                float height = leading + cellpadding;        float rowSpan = (float)cell.rowspan();                switch(cell.verticalAlignment()) {            case Element.ALIGN_BOTTOM:                height *= rowSpan;                break;            case Element.ALIGN_MIDDLE:                height *= (rowSpan / 1.5);                break;            default:                height -= cellpadding * 0.4f;        }                line = new PdfLine(left, right, alignment, height);                ArrayList allActions;        int aCounter;        // we loop over all the elements of the cell        for (Iterator i = cell.getElements(); i.hasNext(); ) {            element = (Element) i.next();            switch(element.type()) {                case Element.JPEG:                case Element.IMGRAW:                case Element.IMGTEMPLATE:                case Element.GIF:                case Element.PNG:                    height = addImage((Image)element, left, right, height, alignment);                    break;                    // if the element is a list                case Element.LIST:                    if (line.size() > 0) {                        line.resetAlignment();                        lines.add(line);                    }                    allActions = new ArrayList();                    processActions(element, null, allActions);                    aCounter = 0;                    ListItem item;                    // we loop over all the listitems                    for (Iterator items = ((List)element).getItems().iterator(); items.hasNext(); ) {                        item = (ListItem) items.next();                        line = new PdfLine(left + item.indentationLeft(), right, alignment, leading);                        line.setListItem(item);                        for (Iterator j = item.getChunks().iterator(); j.hasNext(); ) {                            chunk = new PdfChunk((Chunk) j.next(), (PdfAction)(allActions.get(aCounter++)));                            while ((overflow = line.add(chunk)) != null) {                                lines.add(line);                                line = new PdfLine(left + item.indentationLeft(), right, alignment, leading);                                chunk = overflow;                            }                            line.resetAlignment();                            lines.add(line);                            line = new PdfLine(left + item.indentationLeft(), right, alignment, leading);                        }                    }                    line = new PdfLine(left, right, alignment, leading);                    break;                    // if the element is something else                default:                    allActions = new ArrayList();                    processActions(element, null, allActions);                    aCounter = 0;                    // we loop over the chunks                    for (Iterator j = element.getChunks().iterator(); j.hasNext(); ) {                        Chunk c = (Chunk) j.next();                        chunk = new PdfChunk(c, (PdfAction)(allActions.get(aCounter++)));                        while ((overflow = line.add(chunk)) != null) {                            lines.add(line);                            line = new PdfLine(left, right, alignment, leading);                            chunk = overflow;                        }                    }                    // if the element is a paragraph, section or chapter, we reset the alignment and add the line                    switch (element.type()) {                        case Element.PARAGRAPH:                        case Element.SECTION:                        case Element.CHAPTER:                            line.resetAlignment();                            lines.add(line);                            line = new PdfLine(left, right, alignment, leading);                    }            }        }        if (line.size() > 0) {            lines.add(line);        }        // we set some additional parameters        setBottom(top - leading * (lines.size() - 1) - cellpadding - height - 2 * cellspacing);        this.cellpadding = cellpadding;        this.cellspacing = cellspacing;                rowspan = cell.rowspan();        this.rownumber = rownumber;    }        // overriding of the Rectangle methods        /**     * Returns the lower left x-coordinaat.     *     * @return		the lower left x-coordinaat     */        public float left() {        return super.left(cellspacing);    }        /**     * Returns the upper right x-coordinate.     *     * @return		the upper right x-coordinate     */        public float right() {        return super.right(cellspacing);    }        /**     * Returns the upper right y-coordinate.     *     * @return		the upper right y-coordinate     */        public float top() {        return super.top(cellspacing);    }        /**     * Returns the lower left y-coordinate.     *     * @return		the lower left y-coordinate     */        public float bottom() {        return super.bottom(cellspacing);    }        // methods        /**     * Adds an image to this Cell.     *     * @param   image   the image to add     * @param   left    the left border     * @param   right   the right border     */        private float addImage(Image imageOrg, float left, float right, float height, int alignment) {        Image image = Image.getInstance(imageOrg);        if (image.scaledWidth() > right - left) {            image.scaleToFit(right - left, Float.MAX_VALUE);        }        if (line.size() != 0) lines.add(line);        line = new PdfLine(left, right, alignment, image.scaledHeight() + 0.4f * leading);        lines.add(line);        line = new PdfLine(left, right, alignment, leading);        switch (image.alignment() & Image.MIDDLE) {            case Image.RIGHT:                left = right - image.scaledWidth();                break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -