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

📄 pdfptable.java

📁 一个java操作pdf文件的开发包,很好用的.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * @param rowEnd the last row to be written - 1. If it is -1 all the     * rows to the end are written     * @param xPos the x write coodinate     * @param yPos the y write coodinate     * @param canvases an array of 4 <CODE>PdfContentByte</CODE> obtained from     * <CODE>beginWrittingRows()</CODE>     * @return the y coordinate position of the bottom of the last row     * @see #beginWritingRows(com.lowagie.text.pdf.PdfContentByte)     */        public float writeSelectedRows(int rowStart, int rowEnd, float xPos, float yPos, PdfContentByte[] canvases) {        if (totalWidth <= 0)            throw new RuntimeException("The table width must be greater than zero.");        int size = rows.size();        if (rowEnd < 0)            rowEnd = size;        if (rowStart >= size || rowStart >= rowEnd)            return yPos;        rowEnd = Math.min(rowEnd, size);        float yPosStart = yPos;        for (int k = rowStart; k < rowEnd; ++k) {            PdfPRow row = (PdfPRow)rows.get(k);            row.writeCells(xPos, yPos, canvases);            yPos -= row.getMaxHeights();        }        if (tableEvent != null) {            float heights[] = new float[rowEnd - rowStart + 1];            heights[0] = yPosStart;            for (int k = rowStart; k < rowEnd; ++k) {                PdfPRow row = (PdfPRow)rows.get(k);                heights[k - rowStart + 1] = heights[k - rowStart] - row.getMaxHeights();            }            tableEvent.tableLayout(this, getEventWidths(xPos, rowStart, rowEnd, false), heights, 0, rowStart, canvases);        }        return yPos;    }        /**     * Writes the selected rows to the document.     *      * @param rowStart the first row to be written, zero index     * @param rowEnd the last row to be written - 1. If it is -1 all the     * rows to the end are written     * @param xPos the x write coodinate     * @param yPos the y write coodinate     * @param canvas the <CODE>PdfContentByte</CODE> where the rows will     * be written to     * @return the y coordinate position of the bottom of the last row     */        public float writeSelectedRows(int rowStart, int rowEnd, float xPos, float yPos, PdfContentByte canvas) {        PdfContentByte[] canvases = beginWritingRows(canvas);        float y = writeSelectedRows(rowStart, rowEnd, xPos, yPos, canvases);        endWritingRows(canvases);        return y;    }        /** Gets and initializes the 4 layers where the table is written to. The text or graphics are added to     * one of the 4 <CODE>PdfContentByte</CODE> returned with the following order:<p>     * <ul>     * <li><CODE>PdfPtable.BASECANVAS</CODE> - the original <CODE>PdfContentByte</CODE>. Anything placed here     * will be under the table.     * <li><CODE>PdfPtable.BACKGROUNDCANVAS</CODE> - the layer where the background goes to.     * <li><CODE>PdfPtable.LINECANVAS</CODE> - the layer where the lines go to.     * <li><CODE>PdfPtable.TEXTCANVAS</CODE> - the layer where the text go to. Anything placed here     * will be over the table.     * </ul><p>     * The layers are placed in sequence on top of each other.     * @param canvas the <CODE>PdfContentByte</CODE> where the rows will     * be written to     * @return an array of 4 <CODE>PdfContentByte</CODE>     * @see #writeSelectedRows(int, int, float, float, PdfContentByte[])     */        public static PdfContentByte[] beginWritingRows(PdfContentByte canvas) {        return new PdfContentByte[]{            canvas,            canvas.getDuplicate(),            canvas.getDuplicate(),            canvas.getDuplicate(),        };    }        /** Finishes writing the table.     * @param canvases the array returned by <CODE>beginWritingRows()</CODE>     */        public static void endWritingRows(PdfContentByte[] canvases) {        PdfContentByte canvas = canvases[BASECANVAS];        canvas.saveState();        canvas.add(canvases[BACKGROUNDCANVAS]);        canvas.restoreState();        canvas.saveState();        canvas.setLineCap(2);        canvas.resetRGBColorStroke();        canvas.add(canvases[LINECANVAS]);        canvas.restoreState();        canvas.add(canvases[TEXTCANVAS]);    }        /** Gets the number of rows in this table.     * @return the number of rows in this table     */        public int size() {        return rows.size();    }        /** Gets the total height of the table.     * @return the total height of the table     */        public float getTotalHeight() {        return totalHeight;    }        /** Gets the height of a particular row.     * @param idx the row index (starts at 0)     * @return the height of a particular row     */        public float getRowHeight(int idx) {        if (totalWidth <= 0 || idx < 0 || idx >= rows.size())            return 0;        PdfPRow row = (PdfPRow)rows.get(idx);        return row.getMaxHeights();    }        /** Gets the height of the rows that constitute the header as defined by     * <CODE>setHeaderRows()</CODE>.     * @return the height of the rows that constitute the header     */        public float getHeaderHeight() {        float total = 0;        int size = Math.min(rows.size(), headerRows);        for (int k = 0; k < size; ++k) {            PdfPRow row = (PdfPRow)rows.get(k);            total += row.getMaxHeights();        }        return total;    }        /** Deletes a row from the table.     * @param rowNumber the row to be deleted     * @return <CODE>true</CODE> if the row was deleted     */        public boolean deleteRow(int rowNumber) {        if (rowNumber < 0 || rowNumber >= rows.size()) {            return false;        }        if (totalWidth > 0) {            PdfPRow row = (PdfPRow)rows.get(rowNumber);            totalHeight -= row.getMaxHeights();        }        rows.remove(rowNumber);        return true;    }        /** Deletes the last row in the table.     * @return <CODE>true</CODE> if the last row was deleted     */        public boolean deleteLastRow() {        return deleteRow(rows.size() - 1);    }        /** Gets the number of the rows that constitute the header.     * @return the number of the rows that constitute the header     */    public int getHeaderRows() {        return headerRows;    }        /** Sets the number of the top rows that constitute the header.     * This header has only meaning if the table is added to <CODE>Document</CODE>     * and the table crosses pages.     * @param headerRows the number of the top rows that constitute the header     */    public void setHeaderRows(int headerRows) {        if (headerRows < 0)            headerRows = 0;        this.headerRows = headerRows;    }        /**     * Gets all the chunks in this element.     *     * @return	an <CODE>ArrayList</CODE>     */    public ArrayList getChunks() {        return new ArrayList();    }        /**     * Gets the type of the text element.     *     * @return	a type     */    public int type() {        return Element.PTABLE;    }        /**     * Processes the element by adding it (or the different parts) to an     * <CODE>ElementListener</CODE>.     *     * @param	listener	an <CODE>ElementListener</CODE>     * @return	<CODE>true</CODE> if the element was processed successfully     */    public boolean process(ElementListener listener) {        try {            return listener.add(this);        }        catch(DocumentException de) {            return false;        }    }        /** Gets the width percentage that the table will occupy in the page.     * @return the width percentage that the table will occupy in the page     */    public float getWidthPercentage() {        return widthPercentage;    }        /** Sets the width percentage that the table will occupy in the page.     * @param widthPercentage the width percentage that the table will occupy in the page     */    public void setWidthPercentage(float widthPercentage) {        this.widthPercentage = widthPercentage;    }        /** Gets the horizontal alignment of the table relative to the page.     * @return the horizontal alignment of the table relative to the page     */    public int getHorizontalAlignment() {        return horizontalAlignment;    }        /** Sets the horizontal alignment of the table relative to the page.     * It only has meaning if the width precentage is less than     * 100%.     * @param horizontalAlignment the horizontal alignment of the table relative to the page     */    public void setHorizontalAlignment(int horizontalAlignment) {        this.horizontalAlignment = horizontalAlignment;    }        //add by Jin-Hsia Yang    PdfPRow getRow(int idx) {        return (PdfPRow)rows.get(idx);    }    //end add    /** Sets the table event for this table.     * @param event the table event for this table     */        public void setTableEvent(PdfPTableEvent event) {        tableEvent = event;    }        /** Gets the table event for this page.     * @return the table event for this page     */        public PdfPTableEvent getTableEvent() {        return tableEvent;    }        public float[] getAbsoluteWidths() {        return absoluteWidths;    }        float [][] getEventWidths(float xPos, int firstRow, int lastRow, boolean includeHeaders) {        float widths[][] = new float[(includeHeaders ? headerRows : 0) + lastRow - firstRow][];        if (isColspan) {            int n = 0;            if (includeHeaders) {                for (int k = 0; k < headerRows; ++k)                    widths[n++] = ((PdfPRow)rows.get(k)).getEventWidth(xPos);            }            for (; firstRow < lastRow; ++firstRow)                widths[n++] = ((PdfPRow)rows.get(firstRow)).getEventWidth(xPos);        }        else {            float width[] = new float[absoluteWidths.length + 1];            width[0] = xPos;            for (int k = 0; k < absoluteWidths.length; ++k)                width[k + 1] = width[k] + absoluteWidths[k];            for (int k = 0; k < widths.length; ++k)                widths[k] = width;        }        return widths;    }    /** Getter for property skipFirstHeader.     * @return Value of property skipFirstHeader.     */    public boolean getSkipFirstHeader() {        return skipFirstHeader;    }        /** Skips the printing of the first header. Used when printing     * tables in succession belonging to the same printed table aspect.     * @param skipFirstHeader New value of property skipFirstHeader.     */    public void setSkipFirstHeader(boolean skipFirstHeader) {        this.skipFirstHeader = skipFirstHeader;    }    public void setRunDirection(int runDirection) {        if (runDirection < PdfWriter.RUN_DIRECTION_DEFAULT || runDirection > PdfWriter.RUN_DIRECTION_RTL)            throw new RuntimeException("Invalid run direction: " + runDirection);        this.runDirection = runDirection;    }        public int getRunDirection() {        return runDirection;    }}

⌨️ 快捷键说明

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