List of usage examples for com.lowagie.text.pdf PdfPCell PdfPCell
public PdfPCell(PdfPCell cell)
PdfPCell
. From source file:it.eng.spagobi.engines.qbe.crosstable.exporter.CrosstabPDFExporter.java
License:Mozilla Public License
/** * Builds the table for the crosstab/* w ww. j a v a 2 s . co m*/ * @param json the JSON representation of the crosstab * @param pdfDocument the pdf document that should contains the crosstab * @param numberFormat the formatter for the numbers * @throws JSONException * @throws BadElementException * @throws DocumentException */ public void export(JSONObject json, Document pdfDocument, DecimalFormat numberFormat) throws SerializationException, JSONException, BadElementException, DocumentException { logger.debug("IN: exporting the crosstab"); //prepare the crosstab for the export CrosstabExporterUtility.calculateDescendants(json); JSONObject columnsRoot = (JSONObject) json.get(CrossTab.CROSSTAB_JSON_COLUMNS_HEADERS); JSONArray columnsRootChilds = columnsRoot.getJSONArray(CrossTab.CROSSTAB_NODE_JSON_CHILDS); JSONObject rowsRoot = (JSONObject) json.get(CrossTab.CROSSTAB_JSON_ROWS_HEADERS); JSONArray rowsRootChilds = rowsRoot.getJSONArray(CrossTab.CROSSTAB_NODE_JSON_CHILDS); JSONArray rowHeadersDescription = json.getJSONArray(CrossTab.CROSSTAB_JSON_ROWS_HEADER_TITLE); JSONArray data = (JSONArray) json.get(CrossTab.CROSSTAB_JSON_DATA); measureMetadata = new MeasureFormatter(json, numberFormat, "##,##0.00"); this.numberFormat = numberFormat; //build the matrix for the content dataMatrix = new Vector<List<PdfPCell>>(); buildDataMatrix(data); //number of headers lavels int rowsDepth = CrosstabExporterUtility.getDepth(rowsRoot); int columnsDepth = CrosstabExporterUtility.getDepth(columnsRoot); //build the table PdfPTable table = new PdfPTable(rowsDepth + dataMatrix.get(0).size()); //build the empty cell on the top left PdfPCell topLeftCell = new PdfPCell(new Phrase("")); topLeftCell.setRowspan(columnsDepth - 1);//-1 because of the title of the rows header topLeftCell.setColspan(rowsDepth); topLeftCell.setBorderColor(Color.WHITE); table.addCell(topLeftCell); List<PdfPCell> cells = new ArrayList<PdfPCell>(); //builds the headers int dataColumnNumber = ((JSONArray) data.get(0)).length(); cells.addAll(buildColumnsHeader(columnsRootChilds, rowHeadersDescription, dataColumnNumber)); cells.addAll(buildRowsHeaders(rowsRootChilds)); logger.debug("Addign the content"); //adds the headers for (int i = 0; i < cells.size(); i++) { table.addCell(cells.get(i)); } table.setWidthPercentage(100); pdfDocument.add(table); logger.debug("IN: exported the crosstab"); }
From source file:it.eng.spagobi.engines.qbe.crosstable.exporter.CrosstabPDFExporter.java
License:Mozilla Public License
/** * Build the matrix for the content of the crosstab * @param data/*from w w w . ja va 2 s .com*/ * @throws JSONException */ private void buildDataMatrix(JSONArray data) throws JSONException { logger.debug("IN: building the crosstab content"); PdfPCell cell; for (int i = 0; i < data.length(); i++) { JSONArray array = (JSONArray) data.get(i); List<PdfPCell> dataRow = new ArrayList<PdfPCell>(); for (int j = 0; j < array.length(); j++) { String text = (String) array.get(j); //Check if a cell is a sum if (text.length() > 5 && text.substring(0, 5).equals("[sum]")) { text = text.substring(5); cell = new PdfPCell(new Phrase(getFormattedString(text, i, j), cellFont)); cell.setBackgroundColor(sumBackgroundColor); } else { cell = new PdfPCell(new Phrase(getFormattedString(text, i, j), cellFont)); } cell.setBorderColor(cellsBorderColor); dataRow.add(cell); } dataMatrix.add(dataRow); } logger.debug("OUT: built the crosstab content"); }
From source file:it.eng.spagobi.engines.qbe.crosstable.exporter.CrosstabPDFExporter.java
License:Mozilla Public License
/** * Builds the row headers. This method performs a depth first visit * of the row headers tree/*from ww w . j av a 2 s.com*/ * @param siblings: a level (L) of headers * @return the cells from level L to the leafs * @throws JSONException * @throws BadElementException */ private List<PdfPCell> buildRowsHeaders(JSONArray siblings) throws JSONException, BadElementException { JSONArray childs; List<PdfPCell> rowNodes = new ArrayList<PdfPCell>(); //For every node of the level.. for (int i = 0; i < siblings.length(); i++) { JSONObject aNode = (JSONObject) siblings.get(i); String text = (String) aNode.opt(Node.CROSSTAB_NODE_JSON_DESCRIPTION); if (text == null) { // in case of calculated fields text = (String) aNode.get(CrossTab.CROSSTAB_NODE_JSON_KEY); } int descendants = aNode.getInt(CrosstabExporterUtility.CROSSTAB_JSON_DESCENDANTS_NUMBER); PdfPCell cell = new PdfPCell(new Phrase(text, cellFont)); cell.setBackgroundColor(headersBackgroundColor); cell.setBorderColor(cellsBorderColor); if (descendants > 1) { cell.setRowspan(descendants); } //1) add the node name rowNodes.add(cell); //2) add the child node names childs = aNode.optJSONArray(CrossTab.CROSSTAB_NODE_JSON_CHILDS); if (childs != null && childs.length() > 0) { rowNodes.addAll(buildRowsHeaders(childs)); } else { rowNodes.addAll(dataMatrix.remove(0)); } } return rowNodes; }
From source file:it.eng.spagobi.engines.qbe.crosstable.exporter.CrosstabPDFExporter.java
License:Mozilla Public License
/** * Builds cells for the column headers/*from w w w .j a va 2 s . co m*/ * @param siblings the top level * @return * @throws JSONException * @throws BadElementException */ private List<PdfPCell> buildColumnsHeader(JSONArray siblings, JSONArray rowHeadersDescription, int dataColumnNumber) throws JSONException, BadElementException { List<PdfPCell> cells = new ArrayList<PdfPCell>(); List<JSONObject> columnNodes = getAllNodes(siblings); for (int i = 0; i < columnNodes.size(); i++) { //adds the row headers if (rowHeadersDescription != null && i == columnNodes.size() - dataColumnNumber) { for (int y = 0; y < rowHeadersDescription.length(); y++) { String text = rowHeadersDescription.getString(y); PdfPCell cell = new PdfPCell(new Phrase(text, cellFont)); cell.setBorderColor(cellsBorderColor); cell.setBackgroundColor(headersBackgroundColor); cells.add(cell); } } JSONObject aNode = (JSONObject) columnNodes.get(i); String text = (String) aNode.get(Node.CROSSTAB_NODE_JSON_DESCRIPTION); int descendants = aNode.getInt(CrosstabExporterUtility.CROSSTAB_JSON_DESCENDANTS_NUMBER); PdfPCell cell = new PdfPCell(new Phrase(text, cellFont)); cell.setBorderColor(cellsBorderColor); cell.setBackgroundColor(headersBackgroundColor); if (descendants > 1) { cell.setColspan(descendants); } cells.add(cell); } return cells; }
From source file:it.eng.spagobi.engines.worksheet.exporter.DataSourceTablePDFExporter.java
License:Mozilla Public License
/** * Builds the header of the table../* w ww . ja v a 2 s . c o m*/ * It creates also the object table.. * @param dataStore * @return the table object * @throws BadElementException */ public PdfPTable buildTableHeader(IDataStore dataStore) throws BadElementException { logger.debug("IN: building the headers of the table"); IMetaData dataStoreMetaData = dataStore.getMetaData(); int colunum = dataStoreMetaData.getFieldCount(); List<String> columnsName = new ArrayList<String>(); //reads the names of the visible table columns for (int j = 0; j < colunum; j++) { String fieldName = dataStoreMetaData.getFieldAlias(j); IFieldMetaData fieldMetaData = dataStoreMetaData.getFieldMeta(j); // String format = (String) fieldMetaData.getProperty("format"); String alias = (String) fieldMetaData.getAlias(); if (alias != null && !alias.equals("")) { columnsName.add(alias); } else { columnsName.add(fieldName); } } PdfPTable table = new PdfPTable(colunum); //For each column builds a cell PdfPCell d = table.getDefaultCell(); if (colunum < 4) { table.setWidthPercentage(colunum * 25); } else { table.setWidthPercentage(100); } for (int j = 0; j < colunum; j++) { PdfPCell cell = new PdfPCell(new Phrase(columnsName.get(j))); //cell.setHeader(true); cell.setBorderColor(cellsBorderColor); cell.setBackgroundColor(headerbackgroundColor); table.addCell(cell); } table.setHeaderRows(1); logger.debug("Out: built the headers of the table"); return table; }
From source file:it.eng.spagobi.engines.worksheet.exporter.DataSourceTablePDFExporter.java
License:Mozilla Public License
/** * Build the content of the table//from ww w . j a v a2 s . com * @param dataStore * @param table the table with the headers * @throws BadElementException */ public void buildTableContent(IDataStore dataStore, PdfPTable table) throws BadElementException { logger.debug("IN: building the conetent of the table"); boolean oddRows = true; PdfPCell cell; Iterator it = dataStore.iterator(); IMetaData d = dataStore.getMetaData(); while (it.hasNext()) {//for each record IRecord record = (IRecord) it.next(); List fields = record.getFields(); int length = fields.size(); //build the row for (int fieldIndex = 0; fieldIndex < length; fieldIndex++) { IField f = (IField) fields.get(fieldIndex); IFieldMetaData fieldMetaData = d.getFieldMeta(fieldIndex); String decimalPrecision = (String) fieldMetaData.getProperty(IFieldMetaData.DECIMALPRECISION); if (f == null || f.getValue() == null) { cell = new PdfPCell(new Phrase("")); } else { Class c = d.getFieldType(fieldIndex); cell = new PdfPCell(new Phrase(formatPDFCell(c, f, decimalPrecision))); if (oddRows) { cell.setBackgroundColor(oddrowsBackgroundColor); } else { cell.setBackgroundColor(evenrowsBackgroundColor); } } cell.setBorderColor(cellsBorderColor); table.addCell(cell); } oddRows = !oddRows; } logger.debug("Out: built the conetent of the table"); }
From source file:it.govpay.web.console.pagamenti.gde.exporter.PdfExporter.java
License:Open Source License
private static void createInfospcoopTable(Section subCatPart, Infospcoop infospcoop) throws BadElementException { PdfPTable table = new PdfPTable(2); PdfPCell c1 = new PdfPCell(new Phrase("Infospcoop")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setColspan(2);//from ww w .j a va2 s . co m table.addCell(c1); table.setHeaderRows(1); //riga 1 table.addCell(new Phrase("IdEgov")); table.addCell(new Phrase(infospcoop.getIdEgov())); // riga 2 table.addCell(new Phrase("Soggetto Erogatore")); table.addCell(new Phrase(infospcoop.getTipoSoggettoErogatore() + "/" + infospcoop.getSoggettoErogatore())); // riga 3 table.addCell(new Phrase("Soggetto Fruitore")); table.addCell(new Phrase(infospcoop.getTipoSoggettoFruitore() + "/" + infospcoop.getSoggettoFruitore())); // riga 4 table.addCell(new Phrase("Servizio")); table.addCell(new Phrase(infospcoop.getTipoServizio() + "/" + infospcoop.getServizio())); // riga 5 table.addCell(new Phrase("Azione")); table.addCell(new Phrase(infospcoop.getAzione())); subCatPart.add(table); }
From source file:it.govpay.web.console.pagamenti.gde.exporter.PdfExporter.java
License:Open Source License
private static void createEventoTable(Section subCatPart, Evento evento) throws BadElementException { PdfPTable table = new PdfPTable(2); PdfPCell c1 = new PdfPCell(new Phrase("Evento Id[" + evento.getId() + "]")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setColspan(2);/*from www. jav a 2 s . com*/ table.addCell(c1); table.setHeaderRows(1); //riga 1 if (evento.getData() != null) { table.addCell(new Phrase("Data registrazione")); table.addCell(new Phrase("" + evento.getData())); } //riga 1 if (evento.getDominio() != null) { table.addCell(new Phrase("Id Dominio")); table.addCell(new Phrase(evento.getDominio())); } //riga 1 if (evento.getIuv() != null) { table.addCell(new Phrase("IUV")); table.addCell(new Phrase(evento.getIuv())); } //riga 1 if (evento.getCcp() != null) { table.addCell(new Phrase("CCP")); table.addCell(new Phrase(evento.getCcp())); } //riga 1 if (evento.getPsp() != null) { table.addCell(new Phrase("Id PSP")); table.addCell(new Phrase(evento.getPsp())); } //riga 1 if (evento.getTipoVersamento() != null) { table.addCell(new Phrase("Tipo Versamento")); table.addCell(new Phrase(evento.getTipoVersamento())); } //riga 1 if (evento.getComponente() != null) { table.addCell(new Phrase("Componente")); table.addCell(new Phrase(evento.getComponente().toString())); } //riga 1 if (evento.getCategoria() != null) { table.addCell(new Phrase("Categoria Evento")); table.addCell(new Phrase(evento.getCategoria().toString())); } //riga 1 if (evento.getTipo() != null) { table.addCell(new Phrase("Tipo Evento")); table.addCell(new Phrase(evento.getTipo())); } //riga 1 if (evento.getSottoTipo() != null) { table.addCell(new Phrase("Sottotipo Evento")); table.addCell(new Phrase(evento.getSottoTipo().toString())); } //riga 1 if (evento.getFruitore() != null) { table.addCell(new Phrase("Id Fruitore")); table.addCell(new Phrase(evento.getFruitore())); } //riga 1 if (evento.getErogatore() != null) { table.addCell(new Phrase("Id Erogatore")); table.addCell(new Phrase(evento.getErogatore())); } //riga 1 if (evento.getStazioneIntermediarioPA() != null) { table.addCell(new Phrase("Id Stazione Intermediario PA")); table.addCell(new Phrase(evento.getStazioneIntermediarioPA())); } //riga 1 if (evento.getCanalePagamento() != null) { table.addCell(new Phrase("Canale Pagamento")); table.addCell(new Phrase(evento.getCanalePagamento())); } //riga 1 if (evento.getParametri() != null) { table.addCell(new Phrase("Parametri Specifici Interfaccia")); table.addCell(new Phrase(evento.getParametri())); } if (evento.getEsito() != null) { table.addCell(new Phrase("Esito")); table.addCell(new Phrase(evento.getEsito())); } subCatPart.add(table); }
From source file:jdbreport.model.io.pdf.itext2.PdfWriter.java
License:Apache License
private PdfPCell writeCell(ReportModel model, jdbreport.model.Cell srcCell, int row, int col) throws BadElementException, IOException, SaveReportException { CellStyle style = model.getStyles(srcCell.getStyleId()); java.awt.Rectangle rect = model.getCellRect(row, col, true, true); float h = Math.round((float) Units.PT.setYPixels((int) rect.getHeight())); float w = Math.round((float) Units.PT.setXPixels((int) rect.getWidth())); PdfPCell pdfCell = null;/* ww w. j a v a 2s . c o m*/ if (srcCell.getPicture() != null) { java.awt.Image awtImage = srcCell.getPicture().getImage(); com.lowagie.text.Image image = awtImageToImage(awtImage, srcCell, w, h); pdfCell = new PdfPCell(image); } else { String text = null; if (srcCell.getValue() instanceof CellValue<?>) { StringWriter strWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(strWriter); if (!((CellValue<?>) srcCell.getValue()).write(printWriter, model, row, col, this, ReportBook.PDF)) { java.awt.Image awtImage = ((CellValue<?>) srcCell.getValue()).getAsImage(model, row, col); if (awtImage != null) { com.lowagie.text.Image image = awtImageToImage(awtImage, srcCell, w, h); pdfCell = new PdfPCell(image); } } else { text = strWriter.getBuffer().toString(); } } else { if (jdbreport.model.Cell.TEXT_HTML.equals(srcCell.getContentType())) { pdfCell = new PdfPCell(); writeHTMLText(model.getStyles(srcCell.getStyleId()), srcCell, pdfCell); } else { text = model.getCellText(srcCell); } } if (pdfCell == null) { pdfCell = new PdfPCell(); } if (text != null && text.length() > 0) { com.lowagie.text.Font font; if (fonts.containsKey(style.getId())) { font = fonts.get(style.getId()); } else { font = getFontMapper().styleToPdf(style); fonts.put(style.getId(), font); } Paragraph p; if (font != null) { p = new Paragraph(text, font); } else { p = new Paragraph(text); } pdfCell.setPhrase(p); pdfCell.setPadding(1); pdfCell.setLeading(0f, 1.1f); } else { pdfCell.setPadding(0); } } pdfCell.setFixedHeight(h); pdfCell.setBackgroundColor(style.getBackground()); pdfCell.setHorizontalAlignment(toPdfHAlignment(style.getHorizontalAlignment())); pdfCell.setVerticalAlignment(toPdfVAlignment(style.getVerticalAlignment())); if (style.getAngle() != 0) { pdfCell.setRotation(roundAngle(style.getAngle())); } assignBorders(style, pdfCell); pdfCell.setNoWrap(!style.isWrapLine()); if (srcCell.getColSpan() > 0) { pdfCell.setColspan(srcCell.getColSpan() + 1); } if (srcCell.getRowSpan() > 0) { pdfCell.setRowspan(srcCell.getRowSpan() + 1); } return pdfCell; }
From source file:jm.web.Addons.java
License:GNU General Public License
public static PdfPCell setCeldaPDF(String texto, int tipo, int tamanio, int estilo, int alineacion, int borde) { PdfPCell celda = new PdfPCell(new Paragraph(texto, new Font(tipo, tamanio, estilo))); celda.setHorizontalAlignment(alineacion); celda.setVerticalAlignment(Element.ALIGN_TOP); celda.setBorderColor(Color.LIGHT_GRAY); celda.setBorderWidth(borde);//from w w w. java2s . c o m return celda; }