List of usage examples for com.lowagie.text Table setWidth
public void setWidth(float width)
From source file:org.sigmah.server.report.renderer.itext.ItextTableRenderer.java
License:Open Source License
private void renderTable(Document document, TableData data) throws DocumentException { int colDepth = data.getRootColumn().getDepth(); List<TableColumn> colLeaves = data.getRootColumn().getLeaves(); int colBreadth = colLeaves.size(); Table table = new Table(colBreadth, 1); table.setUseVariableBorders(true);//from w w w . ja v a 2s .c o m table.setWidth(100.0f); table.setBorderWidth(0); // first write the column headers for (int depth = 1; depth <= colDepth; ++depth) { List<TableColumn> columns = data.getRootColumn().getDescendantsAtDepth(depth); for (TableColumn column : columns) { Cell cell = ThemeHelper.columnHeaderCell(column.getLabel(), column.isLeaf(), computeHAlign(column)); cell.setColspan(Math.max(1, column.getChildren().size())); cell.setRowspan(colDepth - depth - column.getDepth() + 1); table.addCell(cell); } } table.endHeaders(); DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM); NumberFormat numberFormat = NumberFormat.getIntegerInstance(); numberFormat.setGroupingUsed(true); for (TableData.Row row : data.getRows()) { for (TableColumn column : colLeaves) { Object value = row.values[data.getColumnIndex(column)]; String label = ""; if (value instanceof Date) { label = dateFormat.format(value); } else if (value instanceof Number) { label = numberFormat.format(value); } else if (value != null) { label = value.toString(); } table.addCell(ThemeHelper.bodyCell(label, false, 0, true, computeHAlign(column))); } } document.add(table); }
From source file:pl.exsio.ca.app.report.terraincard.view.TerrainCardsView.java
License:Open Source License
private Element buildTable(TerrainCardPage page) throws Exception { Table table = new Table(this.viewModel.getTableColumnsNo() * 2); table.setBorderWidth(1);//w w w .j a v a2 s . co m table.setPadding(1); table.setSpacing(1); table.setWidth(100); int currentCol = START_COL; int currentRow = START_ROW; for (int i = 0; i < page.getColumns().size(); i++) { TerrainCardColumn column = page.getColumns().get(i); table.addCell(this.getColumnTitleCell(column.getTerrainName()), 0, currentCol); table.addCell(this.getColumnDescCell("from"), 1, currentCol); table.addCell(this.getColumnDescCell("to"), 1, currentCol + 1); for (int j = 0; j < column.getCells().size(); j++) { TerrainCardCell cell = column.getCells().get(j); boolean odd = j % 2 != 0; table.addCell(this.getNotificationCell(cell.getGroup(), odd, 2), currentRow, currentCol); table.addCell(this.getNotificationCell(cell.getFrom(), odd, 1), currentRow + 1, currentCol); table.addCell(this.getNotificationCell(cell.getTo(), odd, 1), currentRow + 1, currentCol + 1); currentRow += 2; } currentCol += 2; currentRow = START_ROW; } return table; }
From source file:ro.nextreports.engine.exporter.RtfExporter.java
License:Apache License
private Table buildRtfTable(int type) throws DocumentException { List<Band> bands = new ArrayList<Band>(); if (type == 1) { bands.add(getReportLayout().getPageHeaderBand()); } else if (type == 2) { bands.add(getReportLayout().getPageFooterBand()); } else {//from w w w . j a va2 s .c o m bands = getReportLayout().getDocumentBands(); } int totalRows = 0; int totalColumns = 0; for (Band band : bands) { totalRows += band.getRowCount(); int cols = band.getColumnCount(); if (cols > totalColumns) { totalColumns = cols; } } // no page header or no page footer if (totalColumns == 0) { return null; } Table datatable = new Table(totalColumns); int[] headerwidths = new int[totalColumns]; // % int size = 100 / totalColumns; int totalWidth = 0; for (int i = 0; i < totalColumns; i++) { if (bean.getReportLayout().isUseSize()) { headerwidths[i] = bean.getReportLayout().getColumnsWidth().get(i); } else { headerwidths[i] = size; } totalWidth += headerwidths[i]; } if (bean.getReportLayout().isUseSize()) { float pixels = A4_PORTRAIT_PIXELS; if (bean.getReportLayout().getOrientation() == LANDSCAPE) { pixels = A4_LANDSCAPE_PIXELS; } float percentage = totalWidth * 100 / pixels; // do not allow to go outside an A4 frame if (percentage > 100) { percentage = 100; } if (!ReportLayout.CUSTOM.equals(bean.getReportLayout().getPageFormat())) { datatable.setWidth(percentage); } datatable.setWidths(headerwidths); } else { datatable.setWidth(100); } datatable.setPadding(2); if (type == PRINT_DOCUMENT) { writeHeader(datatable); } return datatable; }
From source file:se.idega.idegaweb.commune.school.report.business.ReportPDFWriter.java
License:Open Source License
private MemoryFileBuffer getPDFBuffer() throws DocumentException { MemoryFileBuffer buffer = new MemoryFileBuffer(); MemoryOutputStream mos = new MemoryOutputStream(buffer); Document document = new Document(PageSize.A4, 50, 50, 50, 50); PdfWriter writer = PdfWriter.getInstance(document, mos); String titleKey = this._reportModel.getReportTitleLocalizationKey(); String title = localize(titleKey, titleKey); this._normalFont = new Font(Font.HELVETICA, 7, Font.NORMAL); this._boldFont = new Font(Font.HELVETICA, 7, Font.BOLD); document.addTitle(title);/*from w ww .j ava 2s. com*/ document.addAuthor("Agura IT Reports"); document.addSubject(title); document.open(); String dateString = new Date(System.currentTimeMillis()).toString(); document.add(new Phrase(title + " " + dateString + "\n\n", this._boldFont)); document.add(new Phrase("\n", this._boldFont)); int cols = this._reportModel.getColumnSize() + 1; Table table = new Table(cols); this._widths = new int[cols]; for (int i = 0; i < cols; i++) { this._widths[i] = 1; } table.setSpacing(1.5f); buildColumnHeaders(table); buildRowHeaders(table); buildReportCells(table); int totalWidth = 0; for (int i = 0; i < cols; i++) { this._widths[i] += 1; totalWidth += this._widths[i]; } int width = (100 * totalWidth) / 95; if (width > 100) { width = 100; } table.setWidth(width); table.setWidths(this._widths); document.add(table); document.close(); writer.setPdfVersion(PdfWriter.VERSION_1_2); return buffer; }