List of usage examples for com.itextpdf.text BaseColor BaseColor
public BaseColor(final int argb)
From source file:org.inspira.condominio.pdf.DocumentoEgresos.java
public void exportarPdf(String destino) throws IOException, DocumentException { File file = new File(destino); file.getParentFile().mkdirs();/*ww w. j a v a 2s .co m*/ PdfWriter.getInstance(documento, new FileOutputStream(file)); documento.open(); documento.add(new Paragraph( "Periodo: ".concat( DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault()).format(new Date())), F_NORMAL)); documento.add(new Paragraph(admin, F_NORMAL)); Paragraph heading = new Paragraph("Gastos ".concat(tipoDeGasto), new Font(Font.FontFamily.HELVETICA, 18, Font.BOLD, new BaseColor(0x000000))); heading.setSpacingBefore(16f); heading.setSpacingAfter(16f); Paragraph heading2 = new Paragraph("Autoriz", new Font(Font.FontFamily.HELVETICA, 12, Font.NORMAL, new BaseColor(0x000000))); PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100); Paragraph heading3 = new Paragraph("Vo. Bo.", new Font(Font.FontFamily.HELVETICA, 12, Font.NORMAL, new BaseColor(0x000000))); PdfPCell cell1 = new PdfPCell(heading2); cell1.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell1.setColspan(1); cell1.setFixedHeight(20f); cell1.setBorder(Rectangle.NO_BORDER); PdfPCell cell2 = new PdfPCell(heading3); cell2.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell2.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell2.setColspan(1); cell2.setFixedHeight(20f); cell2.setBorder(Rectangle.NO_BORDER); table.addCell(cell1); table.addCell(cell2); table.setSpacingBefore(16f); table.setSpacingAfter(32f); documento.add(heading); agregarTablaEgresos(egresos); documento.add(table); agregarZonaVistoBueno(); documento.close(); }
From source file:org.inspira.condominio.pdf.DocumentoEgresos.java
private void agregarTablaEgresos(InformacionEgreso[] egresos) throws DocumentException { PdfPCell cell1 = new PdfPCell(new Phrase("Fecha", F_CELL_HEADER_TEXT)); cell1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell1.setColspan(2);//from ww w .j a v a 2 s . com cell1.setFixedHeight(20f); cell1.setBackgroundColor(new BaseColor(0xff009846)); PdfPCell cell2 = new PdfPCell(new Phrase("Descripcin", F_CELL_HEADER_TEXT)); cell2.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell2.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell2.setColspan(6); cell2.setBackgroundColor(new BaseColor(0xff009846)); cell2.setFixedHeight(20f); PdfPCell cell3 = new PdfPCell(new Phrase("Monto", F_CELL_HEADER_TEXT)); cell3.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell3.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell3.setColspan(2); cell3.setBackgroundColor(new BaseColor(0xff009846)); cell3.setFixedHeight(20f); PdfPCell cell4 = new PdfPCell(new Phrase("Pagado con", F_CELL_HEADER_TEXT)); cell4.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell4.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell4.setColspan(2); cell4.setBackgroundColor(new BaseColor(0xff009846)); cell4.setFixedHeight(20f); PdfPCell cell5 = new PdfPCell(new Phrase("Total", F_NORMAL)); cell5.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); cell5.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell5.setColspan(8); cell5.setFixedHeight(20f); PdfPCell cell6 = new PdfPCell(); cell6.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell6.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell6.setColspan(4); cell6.setFixedHeight(20f); PdfPTable table = new PdfPTable(12); table.setWidthPercentage(100); table.addCell(cell1); table.addCell(cell2); table.addCell(cell3); table.addCell(cell4); float total = agregarEgresos(table, egresos); cell5.setBorder(Rectangle.RIGHT); table.addCell(cell5); cell6.setPhrase(new Phrase(String.format("%.2f pesos", total), F_NORMAL)); table.addCell(cell6); documento.add(table); }
From source file:org.inspira.condominio.pdf.DocumentoEstadoDeCuenta.java
private void bakeContent(String path, String imgResString) throws IOException, DocumentException { File outFile = new File(path); outFile.getParentFile().mkdirs();// w w w . j a v a2 s .c o m PdfWriter.getInstance(documento, new FileOutputStream(outFile)); documento.open(); documento.add(new Paragraph( "Ciudad de Mxico, " + DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.getDefault()).format(new Date()), new Font(FontFamily.HELVETICA, 18, Font.NORMAL, new BaseColor(0x000000)))); Paragraph intro = new Paragraph(new Phrase("Comprobante de estado de cuenta", F_NORMAL)); intro.setAlignment(Paragraph.ALIGN_RIGHT); intro.setSpacingBefore(10f); documento.add(intro); Image image = Image.getInstance(imgResString); PdfPTable table = new PdfPTable(1); table.setTotalWidth(image.getScaledWidth()); table.setLockedWidth(true); PdfPCell cell = new PdfPCell(); cell.setBorder(0); //cell.setCellEvent(new ImageBackgroundEvent(image)); cell.setFixedHeight(image.getScaledHeight()); table.addCell(cell); documento.add(table); Paragraph p1 = new Paragraph("Estado de cuenta: ".concat(idEdoCta), F_NORMAL); p1.setSpacingBefore(5f); p1.setSpacingAfter(25f); p1.setAlignment(Paragraph.ALIGN_CENTER); documento.add(p1); documento.add(new Paragraph("Pagos", F_NORMAL)); agregaTablaDePagos(); Paragraph pNotas = new Paragraph("Notas: ".concat(notas), F_NORMAL); pNotas.setSpacingAfter(12f); pNotas.setSpacingAfter(2f); documento.add(pNotas); Paragraph pAdeudos = new Paragraph("Adeudos", F_NORMAL); pAdeudos.setSpacingBefore(25f); documento.add(pAdeudos); agregaTablaDeAdeudos(); documento.add(new Paragraph( "Recuerde que puede consultar su estado de pagos y adeudos desde la aplicacin mvil o directamente con su administrador.", F_NORMAL)); Paragraph hechoPor = new Paragraph("Elabor:", F_NORMAL); hechoPor.setSpacingBefore(30f); hechoPor.setSpacingAfter(15f); documento.add(hechoPor); Paragraph nombreDelAdmin = new Paragraph(admin, F_NORMAL); nombreDelAdmin.setAlignment(Paragraph.ALIGN_CENTER); documento.add(nombreDelAdmin); Paragraph nombreDeCondominio = new Paragraph(condominio, F_NORMAL); nombreDeCondominio.setAlignment(Paragraph.ALIGN_CENTER); documento.add(nombreDeCondominio); }
From source file:org.inspira.condominio.pdf.DocumentoEstadoDeCuenta.java
private float setTableHeading(PdfPTable t1, Ingreso[] ingresos) { PdfPCell cConcepto = new PdfPCell(new Phrase("Concepto", F_CELL_HEADER_TEXT)); cConcepto.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cConcepto.setColspan(3);// www . j ava 2 s . c o m cConcepto.setBackgroundColor(new BaseColor(0xff009846)); t1.addCell(cConcepto); PdfPCell cFecha = new PdfPCell(new Phrase("Fecha", F_CELL_HEADER_TEXT)); cFecha.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cFecha.setColspan(3); cFecha.setBackgroundColor(new BaseColor(0xff009846)); t1.addCell(cFecha); PdfPCell cMonto = new PdfPCell(new Phrase("Monto", F_CELL_HEADER_TEXT)); cMonto.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cMonto.setColspan(3); cMonto.setBackgroundColor(new BaseColor(0xff009846)); t1.addCell(cMonto); PdfPCell concepto; PdfPCell monto; PdfPCell fecha; float total = 0; boolean isTenue = false; for (Ingreso ingreso : ingresos) { concepto = new PdfPCell(); concepto.setColspan(3); concepto.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); if (isTenue) { concepto.setPhrase( new Phrase(ingreso.getConceptoDeIngreso().getConceptoDeIngreso(), F_CELL_HEADER_TEXT)); concepto.setBackgroundColor(new BaseColor(0xaa009846)); } else { concepto.setPhrase(new Phrase(ingreso.getConceptoDeIngreso().getConceptoDeIngreso())); } t1.addCell(concepto); fecha = new PdfPCell(); fecha.setColspan(3); fecha.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); if (isTenue) { fecha.setBackgroundColor(new BaseColor(0xaa009846)); fecha.setPhrase(new Phrase(DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.getDefault()) .format(new Date(ingreso.getFecha())), F_CELL_HEADER_TEXT)); } else { fecha.setPhrase(new Phrase(DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.getDefault()) .format(new Date(ingreso.getFecha())))); } t1.addCell(fecha); monto = new PdfPCell(); monto.setColspan(3); monto.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); if (isTenue) { monto.setBackgroundColor(new BaseColor(0xaa009846)); monto.setPhrase(new Phrase(String.format("%.2f pesos", ingreso.getMonto()), F_CELL_HEADER_TEXT)); } else { monto.setPhrase(new Phrase(String.format("%.2f pesos", ingreso.getMonto()))); } t1.addCell(monto); total += ingreso.getMonto(); isTenue = !isTenue; System.out.println("Total: " + total); } return total; }
From source file:org.inspira.condominio.pdf.DocumentoIngreso.java
public void exportarPdf(String destino, String nombreInmueble, String dir) throws IOException, DocumentException { File file = new File(destino); PdfWriter.getInstance(documento, new FileOutputStream(file)); documento.open();//from w ww . j a v a 2s . c om Paragraph inmueble = new Paragraph(nombreInmueble, new Font(Font.FontFamily.HELVETICA, 26, Font.BOLD, new BaseColor(0x000000))); inmueble.setSpacingAfter(8f); documento.add(inmueble); documento.add(new Paragraph(dir, F_NORMAL)); documento.add(new Paragraph( "Periodo: ".concat( DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.getDefault()).format(new Date())), F_NORMAL)); Paragraph heading = new Paragraph("Formato de ingresos ordinario", new Font(Font.FontFamily.HELVETICA, 18, Font.BOLD, new BaseColor(0x000000))); heading.setSpacingBefore(16f); heading.setSpacingAfter(16f); Paragraph heading2 = new Paragraph("Cobranza ordinaria", new Font(Font.FontFamily.HELVETICA, 18, Font.BOLD, new BaseColor(0x000000))); heading2.setSpacingBefore(16f); heading2.setSpacingAfter(16f); Paragraph heading3 = new Paragraph("Formato de ingresos extraordinario", new Font(Font.FontFamily.HELVETICA, 18, Font.BOLD, new BaseColor(0x000000))); heading3.setSpacingBefore(16f); heading3.setSpacingAfter(16f); Paragraph heading4 = new Paragraph("Cobranza extraordinaria", new Font(Font.FontFamily.HELVETICA, 18, Font.BOLD, new BaseColor(0x000000))); heading4.setSpacingBefore(16f); heading4.setSpacingAfter(16f); documento.add(heading); totalRegular = addTablaFormatoIngresos(infoIngresos); documento.add(heading2); addTablaCobranza(infoIngresos); documento.add(heading3); totalExtra = addTablaFormatoIngresos(infoIngresosExtra); documento.add(heading4); addTablaCobranza(infoIngresosExtra); Paragraph heading5 = new Paragraph( String.format("TOTAL DE INGRESOS: %.2f pesos", totalRegular + totalExtra), new Font(Font.FontFamily.HELVETICA, 18, Font.BOLD, new BaseColor(0x000000))); heading5.setSpacingBefore(16f); heading5.setSpacingAfter(16f); documento.add(heading5); documento.close(); }
From source file:org.inspira.condominio.pdf.DocumentoIngreso.java
private float addTablaFormatoIngresos(InformacionIngresos infoIngresos) throws DocumentException { PdfPCell cellHeader1 = new PdfPCell(new Phrase("Ingresos Ordinarios", F_CELL_HEADER_TEXT)); cellHeader1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cellHeader1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cellHeader1.setColspan(5);/* ww w.j a va 2 s . co m*/ cellHeader1.setFixedHeight(20f); cellHeader1.setBackgroundColor(new BaseColor(0xff009846)); PdfPCell cellHeader2 = new PdfPCell(new Phrase("Monto", F_CELL_HEADER_TEXT)); cellHeader2.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cellHeader2.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cellHeader2.setColspan(5); cellHeader2.setBackgroundColor(new BaseColor(0xff009846)); cellHeader2.setFixedHeight(20f); PdfPCell cellHeader3 = new PdfPCell(new Phrase("En cuenta bancaria", F_NORMAL)); cellHeader3.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cellHeader3.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cellHeader3.setColspan(5); cellHeader3.setFixedHeight(20f); PdfPCell cellHeader4 = new PdfPCell( new Phrase(String.format("%.2f pesos", infoIngresos.getMontoCuentaBancaria()), F_NORMAL)); cellHeader4.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cellHeader4.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cellHeader4.setColspan(5); cellHeader4.setFixedHeight(20f); PdfPCell cellHeader5 = new PdfPCell(new Phrase("En caja de administracin", F_NORMAL)); cellHeader5.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cellHeader5.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cellHeader5.setColspan(5); cellHeader5.setFixedHeight(20f); PdfPCell cellHeader6 = new PdfPCell( new Phrase(String.format("%.2f pesos", infoIngresos.getMontoEnCajaDeAdministracion()), F_NORMAL)); cellHeader6.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cellHeader6.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cellHeader6.setColspan(5); cellHeader6.setFixedHeight(20f); PdfPCell cellHeader7 = new PdfPCell(new Phrase("Total", F_NORMAL)); cellHeader7.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cellHeader7.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cellHeader7.setColspan(5); cellHeader7.setFixedHeight(20f); PdfPCell cellHeader8 = new PdfPCell(new Phrase( String.format("%.2f pesos", infoIngresos.getMontoCuentaBancaria() + infoIngresos.getMontoEnCajaDeAdministracion()), F_NORMAL)); cellHeader8.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cellHeader8.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cellHeader8.setColspan(5); cellHeader8.setFixedHeight(20f); PdfPTable table = new PdfPTable(10); table.setWidthPercentage(100); table.addCell(cellHeader1); table.addCell(cellHeader2); table.addCell(cellHeader3); table.addCell(cellHeader4); table.addCell(cellHeader5); table.addCell(cellHeader6); table.addCell(cellHeader7); table.addCell(cellHeader8); table.setSpacingBefore(3f); documento.add(table); return infoIngresos.getMontoCuentaBancaria() + infoIngresos.getMontoEnCajaDeAdministracion(); }
From source file:org.inspira.condominio.pdf.DocumentoIngreso.java
private void addTablaCobranza(InformacionIngresos infoIngresos) throws DocumentException { PdfPCell cell1 = new PdfPCell(new Phrase("Tipo de condminos", F_CELL_HEADER_TEXT)); cell1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell1.setColspan(6);/* w ww . j a v a2 s .c o m*/ cell1.setFixedHeight(20f); cell1.setBackgroundColor(new BaseColor(0xff009846)); PdfPCell cell2 = new PdfPCell(new Phrase("Nmero", F_CELL_HEADER_TEXT)); cell2.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell2.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell2.setColspan(2); cell2.setBackgroundColor(new BaseColor(0xff009846)); cell2.setFixedHeight(20f); PdfPCell cell3 = new PdfPCell(new Phrase("Porcentaje", F_CELL_HEADER_TEXT)); cell3.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell3.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell3.setColspan(2); cell3.setBackgroundColor(new BaseColor(0xff009846)); cell3.setFixedHeight(20f); PdfPCell cell4 = new PdfPCell(new Phrase("Condminos que efectuaron su pago", F_NORMAL)); cell4.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell4.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell4.setColspan(6); cell4.setFixedHeight(20f); PdfPCell cell5 = new PdfPCell(new Phrase(String.valueOf(infoIngresos.getTotalRegulares()), F_NORMAL)); cell5.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell5.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell5.setColspan(2); cell5.setFixedHeight(20f); PdfPCell cell6 = new PdfPCell(new Phrase(String.format("%.2f%%", ((float) infoIngresos.getTotalRegulares() / (float) infoIngresos.getTotalhabitantes()) * 100), F_NORMAL)); cell6.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell6.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell6.setColspan(2); cell6.setFixedHeight(20f); PdfPCell cell7 = new PdfPCell(new Phrase("Condminos morosos", F_NORMAL)); cell7.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell7.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell7.setColspan(6); cell7.setFixedHeight(20f); PdfPCell cell8 = new PdfPCell(new Phrase( String.valueOf(infoIngresos.getTotalhabitantes() - infoIngresos.getTotalRegulares()), F_NORMAL)); cell8.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell8.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell8.setColspan(2); cell8.setFixedHeight(20f); PdfPCell cell9 = new PdfPCell(new Phrase(String.format("%.2f%%", (((float) infoIngresos.getTotalhabitantes() - (float) infoIngresos.getTotalRegulares()) / (float) infoIngresos.getTotalhabitantes()) * 100), F_NORMAL)); cell9.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell9.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell9.setColspan(2); cell9.setFixedHeight(20f); PdfPCell cell10 = new PdfPCell(new Phrase("Total", F_NORMAL)); cell10.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell10.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell10.setColspan(6); cell10.setFixedHeight(20f); PdfPCell cell11 = new PdfPCell(new Phrase(String.valueOf(infoIngresos.getTotalhabitantes()), F_NORMAL)); cell11.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell11.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell11.setColspan(2); cell11.setFixedHeight(20f); PdfPCell cell12 = new PdfPCell(new Phrase("100%", F_NORMAL)); cell12.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell12.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell12.setColspan(2); cell12.setFixedHeight(20f); PdfPTable table = new PdfPTable(10); table.setWidthPercentage(100); table.addCell(cell1); table.addCell(cell2); table.addCell(cell3); table.addCell(cell4); table.addCell(cell5); table.addCell(cell6); table.addCell(cell7); table.addCell(cell8); table.addCell(cell9); table.addCell(cell10); table.addCell(cell11); table.addCell(cell12); documento.add(table); }
From source file:ro.nextreports.engine.exporter.PdfExporter.java
License:Apache License
private PdfPCell renderPdfCell(BandElement bandElement, Object value, int gridRow, int rowSpan, int colSpan, boolean image, int column) { Map<String, Object> style = buildCellStyleMap(bandElement, value, gridRow, column, colSpan); FontFactoryImp fact = new FontFactoryImp(); com.itextpdf.text.Font fnt;/* w w w .j a v a 2 s.c om*/ if (bandElement != null) { fontName = (String) style.get(StyleFormatConstants.FONT_NAME_KEY); int size = ((Float) style.get(StyleFormatConstants.FONT_SIZE)).intValue(); fnt = getFont(size); } else { fnt = getFont(10); } PdfPCell cell; if (image) { if (value == null) { cell = new PdfPCell(new Phrase(IMAGE_NOT_FOUND)); } else { ImageBandElement ibe = (ImageBandElement) bandElement; try { byte[] imageBytes = getImage((String) value); cell = getImageCell(ibe, imageBytes, column, colSpan); } catch (Exception e) { cell = new PdfPCell(new Phrase(IMAGE_NOT_LOADED)); } } } else if (bandElement instanceof HyperlinkBandElement) { Hyperlink hyperlink = ((HyperlinkBandElement) bandElement).getHyperlink(); Anchor anchor = new Anchor(hyperlink.getText(), fnt); anchor.setReference(hyperlink.getUrl()); Phrase ph = new Phrase(); ph.add(anchor); cell = new PdfPCell(ph); } else if (bandElement instanceof ReportBandElement) { Report report = ((ReportBandElement) bandElement).getReport(); ExporterBean eb = null; try { eb = getSubreportExporterBean(report); PdfExporter subExporter = new PdfExporter(eb); subExporter.export(); PdfPTable innerTable = subExporter.getTable(); cell = new PdfPCell(innerTable); } catch (Exception e) { cell = new PdfPCell(); e.printStackTrace(); } finally { if ((eb != null) && (eb.getResult() != null)) { eb.getResult().close(); } } } else if ((bandElement instanceof VariableBandElement) && (VariableFactory .getVariable(((VariableBandElement) bandElement).getVariable()) instanceof TotalPageNoVariable)) { try { cell = new PdfPCell(Image.getInstance(total)); } catch (BadElementException e) { cell = new PdfPCell(new Phrase("NA")); } } else if (bandElement instanceof ImageColumnBandElement) { try { String v = StringUtil.getValueAsString(value, null); if (StringUtil.BLOB.equals(v)) { cell = new PdfPCell(new Phrase(StringUtil.BLOB)); } else { byte[] bytes = StringUtil.decodeImage(v); cell = getImageCell(bandElement, bytes, column, colSpan); } } catch (Exception e) { e.printStackTrace(); cell = new PdfPCell(new Phrase(IMAGE_NOT_LOADED)); } } else { String stringValue; if (style.containsKey(StyleFormatConstants.PATTERN)) { stringValue = StringUtil.getValueAsString(value, (String) style.get(StyleFormatConstants.PATTERN), getReportLanguage()); } else { stringValue = StringUtil.getValueAsString(value, null, getReportLanguage()); } if (stringValue == null) { stringValue = ""; } if (stringValue.startsWith("<html>")) { StringReader reader = new StringReader(stringValue); List<Element> elems = new ArrayList<Element>(); try { elems = HTMLWorker.parseToList(reader, new StyleSheet()); Phrase ph = new Phrase(); for (int i = 0; i < elems.size(); i++) { Element elem = (Element) elems.get(i); ph.add(elem); } cell = new PdfPCell(ph); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); Phrase ph = new Phrase(stringValue, fnt); cell = new PdfPCell(ph); } } else { Phrase ph = new Phrase(stringValue, fnt); cell = new PdfPCell(ph); } } cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell.setUseDescender(true); // needed for a cell without padding cell.setMinimumHeight(MINIMUM_HEIGHT); // needed if there is a row in which all cells are empty if (bandElement != null) { cell.setRotation(bandElement.getTextRotation()); } if (colSpan > 1) { cell.setColspan(colSpan); } if (rowSpan > 1) { cell.setRowspan(rowSpan); } if (style != null) { updateFont(style, fnt); if (style.containsKey(StyleFormatConstants.BACKGROUND_COLOR)) { Color val = (Color) style.get(StyleFormatConstants.BACKGROUND_COLOR); cell.setBackgroundColor(new BaseColor(val)); } if (style.containsKey(StyleFormatConstants.HORIZONTAL_ALIGN_KEY)) { if (StyleFormatConstants.HORIZONTAL_ALIGN_LEFT .equals(style.get(StyleFormatConstants.HORIZONTAL_ALIGN_KEY))) { cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); } if (StyleFormatConstants.HORIZONTAL_ALIGN_RIGHT .equals(style.get(StyleFormatConstants.HORIZONTAL_ALIGN_KEY))) { cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); } if (StyleFormatConstants.HORIZONTAL_ALIGN_CENTER .equals(style.get(StyleFormatConstants.HORIZONTAL_ALIGN_KEY))) { cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); } } if (style.containsKey(StyleFormatConstants.VERTICAL_ALIGN_KEY)) { if (StyleFormatConstants.VERTICAL_ALIGN_TOP .equals(style.get(StyleFormatConstants.VERTICAL_ALIGN_KEY))) { cell.setVerticalAlignment(Element.ALIGN_TOP); } if (StyleFormatConstants.VERTICAL_ALIGN_MIDDLE .equals(style.get(StyleFormatConstants.VERTICAL_ALIGN_KEY))) { cell.setVerticalAlignment(Element.ALIGN_MIDDLE); } if (StyleFormatConstants.VERTICAL_ALIGN_BOTTOM .equals(style.get(StyleFormatConstants.VERTICAL_ALIGN_KEY))) { cell.setVerticalAlignment(Element.ALIGN_BOTTOM); } } if (style.containsKey(StyleFormatConstants.PADDING_LEFT)) { Float val = (Float) style.get(StyleFormatConstants.PADDING_LEFT); cell.setPaddingLeft(val); } if (style.containsKey(StyleFormatConstants.PADDING_RIGHT)) { Float val = (Float) style.get(StyleFormatConstants.PADDING_RIGHT); cell.setPaddingRight(val); } if (style.containsKey(StyleFormatConstants.PADDING_TOP)) { Float val = (Float) style.get(StyleFormatConstants.PADDING_TOP); cell.setPaddingTop(val); } if (style.containsKey(StyleFormatConstants.PADDING_BOTTOM)) { Float val = (Float) style.get(StyleFormatConstants.PADDING_BOTTOM); cell.setPaddingBottom(val); } cell.setBorderWidth(0); if (style.containsKey(StyleFormatConstants.BORDER_LEFT)) { Float val = (Float) style.get(StyleFormatConstants.BORDER_LEFT); cell.setBorderWidthLeft(val / 2); Color color = (Color) style.get(StyleFormatConstants.BORDER_LEFT_COLOR); cell.setBorderColorLeft(new BaseColor(color)); } if (style.containsKey(StyleFormatConstants.BORDER_RIGHT)) { Float val = (Float) style.get(StyleFormatConstants.BORDER_RIGHT); cell.setBorderWidthRight(val / 2); Color color = (Color) style.get(StyleFormatConstants.BORDER_RIGHT_COLOR); cell.setBorderColorRight(new BaseColor(color)); } if (style.containsKey(StyleFormatConstants.BORDER_TOP)) { Float val = (Float) style.get(StyleFormatConstants.BORDER_TOP); cell.setBorderWidthTop(val / 2); Color color = (Color) style.get(StyleFormatConstants.BORDER_TOP_COLOR); cell.setBorderColorTop(new BaseColor(color)); } if (style.containsKey(StyleFormatConstants.BORDER_BOTTOM)) { Float val = (Float) style.get(StyleFormatConstants.BORDER_BOTTOM); cell.setBorderWidthBottom(val / 2); Color color = (Color) style.get(StyleFormatConstants.BORDER_BOTTOM_COLOR); cell.setBorderColorBottom(new BaseColor(color)); } // for subreports we use default no wrap if (cell.getTable() == null) { cell.setNoWrap(true); if (bandElement != null) { if (bandElement.isWrapText()) { cell.setNoWrap(false); } } } // to see a background image all cells must not have any background! if (bean.getReportLayout().getBackgroundImage() != null) { cell.setBackgroundColor(null); } } return cell; }
From source file:ro.nextreports.engine.exporter.PdfExporter.java
License:Apache License
private void updateFont(Map<String, Object> style, Font fnt) { if (style.containsKey(StyleFormatConstants.FONT_FAMILY_KEY)) { String val = (String) style.get(StyleFormatConstants.FONT_FAMILY_KEY); fnt.setFamily(val); }/*w ww . j a v a 2 s .c o m*/ if (style.containsKey(StyleFormatConstants.FONT_SIZE)) { Float val = (Float) style.get(StyleFormatConstants.FONT_SIZE); fnt.setSize(val); } if (style.containsKey(StyleFormatConstants.FONT_COLOR)) { Color val = (Color) style.get(StyleFormatConstants.FONT_COLOR); fnt.setColor(new BaseColor(val)); } if (style.containsKey(StyleFormatConstants.FONT_STYLE_KEY)) { if (StyleFormatConstants.FONT_STYLE_NORMAL.equals(style.get(StyleFormatConstants.FONT_STYLE_KEY))) { fnt.setStyle(Font.NORMAL); } if (StyleFormatConstants.FONT_STYLE_BOLD.equals(style.get(StyleFormatConstants.FONT_STYLE_KEY))) { fnt.setStyle(Font.BOLD); } if (StyleFormatConstants.FONT_STYLE_ITALIC.equals(style.get(StyleFormatConstants.FONT_STYLE_KEY))) { fnt.setStyle(Font.ITALIC); } if (StyleFormatConstants.FONT_STYLE_BOLDITALIC.equals(style.get(StyleFormatConstants.FONT_STYLE_KEY))) { fnt.setStyle(Font.BOLDITALIC); } } }