table.java
来自「有关对pdf操作的代码」· Java 代码 · 共 1,491 行 · 第 1/4 页
JAVA
1,491 行
public Cell getDefaultCell() { return defaultCell; } /** * Sets the default layout of the Table to * the provided Cell * @param value a cell with all the defaults * @since 2.0.7 */ public void setDefaultCell(Cell value) { defaultCell = value; } /** * Gets the last number of the rows that contain headers. * * @return a rownumber */ public int getLastHeaderRow() { return this.lastHeaderRow; } /** * Sets the horizontal alignment. * * @param value the new value */ public void setLastHeaderRow(int value) { lastHeaderRow = value; } /** * Marks the last row of the table headers. * * @return the number of the last row of the table headers */ public int endHeaders() { lastHeaderRow = curPosition.x - 1; return lastHeaderRow; } /** * Gets the horizontal alignment. * * @return a value */ public int getAlignment() { return alignment; } /** * Sets the horizontal alignment. * * @param value the new value */ public void setAlignment(int value) { alignment = value; } /** * Sets the alignment of this paragraph. * * @param alignment the new alignment as a <CODE>String</CODE> */ public void setAlignment(String alignment) { if (ElementTags.ALIGN_LEFT.equalsIgnoreCase(alignment)) { this.alignment = Element.ALIGN_LEFT; return; } if (ElementTags.RIGHT.equalsIgnoreCase(alignment)) { this.alignment = Element.ALIGN_RIGHT; return; } this.alignment = Element.ALIGN_CENTER; } /** * Gets the cellpadding. * * @return a value */ public float getPadding() { return cellpadding; } /** * Sets the cellpadding. * * @param value the new value */ public void setPadding(float value) { cellpadding = value; } /** * Gets the cellspacing. * * @return a value */ public float getSpacing() { return cellspacing; } /** * Sets the cellspacing. * * @param value the new value */ public void setSpacing(float value) { cellspacing = value; } /** * Enables/disables automatic insertion of empty cells before table is rendered. (default = false) * As some people may want to create a table, fill only a couple of the cells and don't bother with * investigating which empty ones need to be added, this default behavior may be very welcome. * Disabling is recommended to increase speed. (empty cells should be added through extra code then) * * @param aDoAutoFill enable/disable autofill */ public void setAutoFillEmptyCells(boolean aDoAutoFill) { autoFillEmptyCells = aDoAutoFill; } /** * Gets the table width (a percentage). * * @return the table width */ public float getWidth() { return width; } /** * Sets the width of this table (in percentage of the available space). * * @param width the width */ public void setWidth(float width) { this.width = width; } /** * @return the locked */ public boolean isLocked() { return locked; } /** * @param locked the locked to set */ public void setLocked(boolean locked) { this.locked = locked; } /** * Gets the proportional widths of the columns in this <CODE>Table</CODE>. * * @return the proportional widths of the columns in this <CODE>Table</CODE> */ public float[] getProportionalWidths() { return widths; } /** * Sets the widths of the different columns (percentages). * <P> * You can give up relative values of borderwidths. * The sum of these values will be considered 100%. * The values will be recalculated as percentages of this sum. * <P> * example: * <BLOCKQUOTE><PRE> * float[] widths = {2, 1, 1}; * <STRONG>table.setWidths(widths)</STRONG> * </PRE></BLOCKQUOTE> * The widths will be: a width of 50% for the first column, * 25% for the second and third column. * * @param widths an array with values * @throws BadElementException */ public void setWidths(float[] widths) throws BadElementException { if (widths.length != columns) { throw new BadElementException("Wrong number of columns."); } // The sum of all values is 100% float hundredPercent = 0; for (int i = 0; i < columns; i++) { hundredPercent += widths[i]; } // The different percentages are calculated float width; this.widths[columns - 1] = 100; for (int i = 0; i < columns - 1; i++) { width = (100.0f * widths[i]) / hundredPercent; this.widths[i] = width; this.widths[columns - 1] -= width; } } /** * Sets the widths of the different columns (percentages). * <P> * You can give up relative values of borderwidths. * The sum of these values will be considered 100%. * The values will be recalculated as percentages of this sum. * * @param widths an array with values * @throws DocumentException */ public void setWidths(int[] widths) throws DocumentException { float tb[] = new float[widths.length]; for (int k = 0; k < widths.length; ++k) tb[k] = widths[k]; setWidths(tb); } /** * Checks if this <CODE>Table</CODE> has to fit a page. * * @return true if the table may not be split */ public boolean isTableFitsPage() { return tableFitsPage; } /** * Allows you to control when a page break occurs. * <P> * When a table doesn't fit a page, it is split in two parts. * If you want to avoid this, you should set the <VAR>tableFitsPage</VAR> value to true. * * @param fitPage enter true if you don't want to split cells */ public void setTableFitsPage(boolean fitPage) { this.tableFitsPage = fitPage; if (fitPage) setCellsFitPage(true); } /** * Checks if the cells of this <CODE>Table</CODE> have to fit a page. * * @return true if the cells may not be split */ public boolean isCellsFitPage() { return cellsFitPage; } /** * Allows you to control when a page break occurs. * <P> * When a cell doesn't fit a page, it is split in two parts. * If you want to avoid this, you should set the <VAR>cellsFitPage</VAR> value to true. * * @param fitPage enter true if you don't want to split cells */ public void setCellsFitPage(boolean fitPage) { this.cellsFitPage = fitPage; } /** * Sets the offset of this table. * * Normally a newline is added before you add a Table object. * This newline uses the current leading. * If you want to control the space between the table and the previous * element yourself, you have to set the offset of this table. * * @param offset the space between this table and the previous object. */ public void setOffset(float offset) { this.offset = offset; } /** * Gets the offset of this table. * * @return the space between this table and the previous element. */ public float getOffset() { return offset; } /** * Method to check if the Table should be converted to a PdfPTable or not. * @return false if the table should be handled the old fashioned way. */ public boolean isConvert2pdfptable() { return convert2pdfptable; } /** * If set to true, iText will try to convert the Table to a PdfPTable. * @param convert2pdfptable true if you want iText to try to convert the Table to a PdfPTable */ public void setConvert2pdfptable(boolean convert2pdfptable) { this.convert2pdfptable = convert2pdfptable; } // methods to add content to the table /** * Adds a <CODE>Cell</CODE> to the <CODE>Table</CODE> at a certain row and column. * * @param aCell The <CODE>Cell</CODE> to add * @param row The row where the <CODE>Cell</CODE> will be added * @param column The column where the <CODE>Cell</CODE> will be added * @throws BadElementException */ public void addCell(Cell aCell, int row, int column) throws BadElementException { addCell(aCell, new Point(row,column)); } /** * Adds a <CODE>Cell</CODE> to the <CODE>Table</CODE> at a certain location. * * @param aCell The <CODE>Cell</CODE> to add * @param aLocation The location where the <CODE>Cell</CODE> will be added * @throws BadElementException */ public void addCell(Cell aCell, Point aLocation) throws BadElementException { if (aCell == null) throw new NullPointerException("addCell - cell has null-value"); if (aLocation == null) throw new NullPointerException("addCell - point has null-value"); if (aCell.isTable()) insertTable((Table)aCell.getElements().next(), aLocation); if (aLocation.x < 0) throw new BadElementException("row coordinate of location must be >= 0"); if ((aLocation.y <= 0) && (aLocation.y > columns)) throw new BadElementException("column coordinate of location must be >= 0 and < nr of columns"); if (!isValidLocation(aCell, aLocation)) throw new BadElementException("Adding a cell at the location (" + aLocation.x + "," + aLocation.y + ") with a colspan of " + aCell.getColspan() + " and a rowspan of " + aCell.getRowspan() + " is illegal (beyond boundaries/overlapping)."); if (aCell.getBorder() == UNDEFINED) aCell.setBorder(defaultCell.getBorder()); aCell.fill(); placeCell(rows, aCell, aLocation); setCurrentLocationToNextValidPosition(aLocation); } /** * Adds a <CODE>Cell</CODE> to the <CODE>Table</CODE>. * * @param cell a <CODE>Cell</CODE> */ public void addCell(Cell cell) { try { addCell(cell, curPosition); } catch(BadElementException bee) { // don't add the cell } } /** * Adds a <CODE>Cell</CODE> to the <CODE>Table</CODE>. * <P> * This is a shortcut for <CODE>addCell(Cell cell)</CODE>. * The <CODE>Phrase</CODE> will be converted to a <CODE>Cell</CODE>. * * @param content a <CODE>Phrase</CODE> * @throws BadElementException this should never happen */ public void addCell(Phrase content) throws BadElementException { addCell(content, curPosition); } /** * Adds a <CODE>Cell</CODE> to the <CODE>Table</CODE>. * <P> * This is a shortcut for <CODE>addCell(Cell cell, Point location)</CODE>. * The <CODE>Phrase</CODE> will be converted to a <CODE>Cell</CODE>. * * @param content a <CODE>Phrase</CODE>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?