List of usage examples for com.lowagie.text Element ALIGN_MIDDLE
int ALIGN_MIDDLE
To view the source code for com.lowagie.text Element ALIGN_MIDDLE.
Click Source Link
From source file:com.qcadoo.report.internal.PdfHelperImpl.java
License:Open Source License
private PdfPTable setTableProperties(final List<String> header, final boolean lastColumnAligmentToLeft, final PdfPTable table, final Map<String, HeaderAlignment> alignments) { table.setWidthPercentage(100f);// w w w .j ava2s . com table.setHorizontalAlignment(Element.ALIGN_LEFT); table.setSpacingBefore(7.0f); // table.getDefaultCell().setBackgroundColor(ColorUtils.getBackgroundColor()); table.getDefaultCell().setBorderColor(ColorUtils.getLineDarkColor()); table.getDefaultCell().setBorderWidth(1.0f); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); table.getDefaultCell().setPadding(5.0f); table.getDefaultCell().disableBorderSide(Rectangle.RIGHT); if (alignments == null || alignments.isEmpty()) { table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); int i = 0; for (String element : header) { i++; if (i == header.size()) { table.getDefaultCell().enableBorderSide(Rectangle.RIGHT); } table.addCell(new Phrase(element, FontUtils.getDejavuBold7Dark())); if (i == 1) { table.getDefaultCell().disableBorderSide(Rectangle.LEFT); } } } else { int i = 0; for (String element : header) { i++; HeaderAlignment alignment = alignments.get(element); if (HeaderAlignment.LEFT.equals(alignment)) { table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); } else if (HeaderAlignment.RIGHT.equals(alignment)) { table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); } if (i == header.size()) { table.getDefaultCell().enableBorderSide(Rectangle.RIGHT); } table.addCell(new Phrase(element, FontUtils.getDejavuBold7Dark())); if (i == 1) { table.getDefaultCell().disableBorderSide(Rectangle.LEFT); } } } table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(null); table.getDefaultCell().disableBorderSide(Rectangle.RIGHT); table.getDefaultCell().setBorderColor(ColorUtils.getLineLightColor()); return table; }
From source file:com.silverpeas.kmelia.workflowextensions.SendInKmelia.java
License:Open Source License
private void generatePDFStepHeader(HistoryStep step, com.lowagie.text.Document document) { try {/*from w w w. jav a 2 s . co m*/ String activity = ""; if (step.getResolvedState() != null) { State resolvedState = step.getProcessInstance().getProcessModel().getState(step.getResolvedState()); activity = resolvedState.getLabel(getRole(), getLanguage()); } String sAction = null; try { if ("#question#".equals(step.getAction())) { sAction = getString("processManager.question"); } else if ("#response#".equals(step.getAction())) { sAction = getString("processManager.response"); } else if ("#reAssign#".equals(step.getAction())) { sAction = getString("processManager.reAffectation"); } else { Action action = step.getProcessInstance().getProcessModel().getAction(step.getAction()); sAction = action.getLabel(getRole(), getLanguage()); } } catch (WorkflowException we) { sAction = "##"; } String actor = getBestUserDetail().getDisplayedName(); String date = DateUtil.getOutputDateAndHour(step.getActionDate(), getLanguage()); String header = ""; if (StringUtil.isDefined(activity)) { header += activity + " - "; } header += sAction + " (" + actor + " - " + date + ")"; Font fontHeader = new Font(Font.HELVETICA, 12, Font.NORMAL); PdfPCell pCell = new PdfPCell(new Phrase(header, fontHeader)); pCell.setFixedHeight(28); pCell.setBackgroundColor(new Color(239, 239, 239)); pCell.setVerticalAlignment(Element.ALIGN_MIDDLE); PdfPTable pTable = new PdfPTable(1); pTable.setWidthPercentage(100); pTable.addCell(pCell); document.add(pTable); } catch (Exception e) { SilverTrace.error("workflowEngine", "SendInKmelia.generatePDFStep()", "root.MSG_GEN_ERROR", e); } }
From source file:com.tsp.gespro.bo.DegustacionBO.java
/** * Representacin impresa PDF//from w ww . ja va 2 s.co m */ public ByteArrayOutputStream toPdf(UsuarioBO user) throws Exception { SimpleDateFormat fecha = new SimpleDateFormat("dd/MM/yyyy"); SimpleDateFormat hora = new SimpleDateFormat("HH:mm:ss"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfITextUtil obj = new PdfITextUtil(); //Tamao de documento (Tamao Carta) com.lowagie.text.Document doc = new com.lowagie.text.Document(PageSize.LETTER); //Definicin de Fuentes a usar Font letraOcho = new Font(Font.HELVETICA, 8, Font.NORMAL); Font letraOchoBold = new Font(Font.HELVETICA, 8, Font.BOLD); Font letraNueve = new Font(Font.HELVETICA, 9, Font.NORMAL); Font letraNueveBold = new Font(Font.HELVETICA, 9, Font.BOLD); Font letraNueveBoldRojo = new Font(Font.TIMES_ROMAN, 9, Font.BOLD, Color.red); Font letraNueveBoldAzul = new Font(Font.TIMES_ROMAN, 9, Font.BOLD, Color.blue); Font letraOchoVerde = new Font(Font.TIMES_ROMAN, 8, Font.NORMAL, Color.green); Font letra14Bold = new Font(Font.HELVETICA, 14, Font.BOLD); String msgError = ""; File fileImageLogo = null; try { if (user != null) fileImageLogo = new ImagenPersonalBO(this.conn) .getFileImagenPersonalByEmpresa(user.getUser().getIdEmpresa()); } catch (Exception ex) { ex.printStackTrace(); } try { //Preparamos writer de PDF PdfWriter writer = PdfWriter.getInstance(doc, baos); EventPDF eventPDF = new EventPDF(doc, user, ReportBO.DEGUSTACION_REPRESENTACION_IMPRESA, fileImageLogo); writer.setPageEvent(eventPDF); //Ajustamos margenes de pgina //doc.setMargins(50, 50, 120, 50); //doc.setMargins(20, 20, 80, 20); doc.setMargins(10, 10, 150, 40); //Iniciamos documento doc.open(); //Creamos tabla principal PdfPTable mainTable = new PdfPTable(1); mainTable.setTotalWidth(550); mainTable.setLockedWidth(true); //CONTENIDO ------------- //SALTO DE L?NEA obj.agregaCelda(mainTable, letraOcho, " ", new boolean[] { false, false, false, false }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0, new int[0], 1); //Cabecera (Datos Generales)--------------------- PdfPTable tAux = new PdfPTable(1); Cliente clienteDto = null; DatosUsuario datosUsuarioVendedor = null; try { if (this.degustacion.getIdCliente() > 0) clienteDto = new ClienteBO(this.degustacion.getIdCliente(), this.conn).getCliente(); if (this.degustacion.getIdUsuario() > 0) datosUsuarioVendedor = new UsuarioBO(this.degustacion.getIdUsuario()).getDatosUsuario(); } catch (Exception ex) { ex.printStackTrace(); } //Datos informativos generales PdfPTable tInfoGeneral = new PdfPTable(1); tInfoGeneral.setTotalWidth(160); tInfoGeneral.setLockedWidth(true); obj.agregaCelda(tInfoGeneral, letraNueveBold, Color.lightGray, "ID Degustacin", new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0, new int[0], 1); obj.agregaCelda(tInfoGeneral, letraNueveBoldRojo, "" + this.degustacion.getIdDegustacion(), new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0, new int[0], 1); obj.agregaCelda(tInfoGeneral, letraNueveBold, Color.lightGray, "Fecha Degustacin", new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0, new int[0], 1); obj.agregaCelda(tInfoGeneral, letraNueve, DateManage.dateToStringEspanol(this.degustacion.getFechaApertura()), new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0, new int[0], 1); obj.agregaCelda(tInfoGeneral, letraNueveBold, Color.lightGray, "Promotor", new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0, new int[0], 1); obj.agregaCelda(tInfoGeneral, letraNueve, datosUsuarioVendedor != null ? (datosUsuarioVendedor.getNombre() + " " + datosUsuarioVendedor.getApellidoPat()) : "Sin vendedor asignado", new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0, new int[0], 1); //Pintamos datos informativos Generales en la esquina superior derecha PdfContentByte cb = writer.getDirectContent(); tInfoGeneral.writeSelectedRows(0, -1, doc.right() - 180, doc.top() + 100, cb); //Datos de Cliente/Prospecto PdfPTable tCliente = new PdfPTable(2); tCliente.setTotalWidth(550); tCliente.setLockedWidth(true); obj.agregaCelda(tCliente, letraNueveBold, Color.lightGray, "Cliente", new boolean[] { false, false, false, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0, new int[0], 2); tAux = new PdfPTable(1); tAux.setTotalWidth(275); tAux.setLockedWidth(true); try { obj.agregaCelda(tAux, letraOcho, "Nombre Comercial: " + (clienteDto != null ? clienteDto.getNombreComercial() : ""), new boolean[] { false, true, false, false }, Element.ALIGN_LEFT, Element.ALIGN_TOP, 0, new int[0], 1); } catch (Exception ex) { ex.printStackTrace(); } obj.agregaTabla(tCliente, tAux, new boolean[] { false, false, false, false }, Element.ALIGN_LEFT, Element.ALIGN_TOP, 0, new int[0], 1); obj.agregaCelda(tCliente, letraOcho, "" + "DOMICILIO: \n" + (clienteDto != null ? "Calle: " + clienteDto.getCalle() : "") + " " + (clienteDto != null ? clienteDto.getNumero() : "") + " " + (clienteDto != null ? clienteDto.getNumeroInterior() : "") + (clienteDto != null ? " Col: " + clienteDto.getColonia() : "") + (clienteDto != null ? " \nDeleg./Municipio: " + clienteDto.getMunicipio() : "") + (clienteDto != null ? " Estado: " + clienteDto.getEstado() : "") + (clienteDto != null ? " \nC.P. " + clienteDto.getCodigoPostal() : ""), new boolean[] { false, true, false, true }, Element.ALIGN_LEFT, Element.ALIGN_TOP, 0, new int[0], 1); obj.agregaTabla(mainTable, tCliente, new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_TOP, 0, new int[0], 1); //FIN Cabecera (Datos Generales)----------------- //DOBLE SALTO DE L?NEA obj.agregaCelda(mainTable, letraOcho, null, " ", new boolean[] { false, false, false, false }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0, new int[0], 1); obj.agregaCelda(mainTable, letraOcho, null, " ", new boolean[] { false, false, false, false }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0, new int[0], 1); int colsDetalles = 6; PdfPTable tDetalles = new PdfPTable(colsDetalles);//6); tDetalles.setTotalWidth(550); tDetalles.setWidths(new int[] { 200, 70, 70, 70, 70, 70 }); tDetalles.setLockedWidth(true); /*CABECERA*/ obj.agregaCelda(tDetalles, letraNueveBold, Color.lightGray, "Producto Degustado", new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15, new int[] { 5, 5, 5, 5 }, 1); obj.agregaCelda(tDetalles, letraNueveBold, Color.lightGray, "Hr Inicio", new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15, new int[] { 5, 5, 5, 5 }, 1); obj.agregaCelda(tDetalles, letraNueveBold, Color.lightGray, "Hr Termino", new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15, new int[] { 5, 5, 5, 5 }, 1); obj.agregaCelda(tDetalles, letraNueveBold, Color.lightGray, "Inventario Inicial", new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15, new int[] { 5, 5, 5, 5 }, 1); obj.agregaCelda(tDetalles, letraNueveBold, Color.lightGray, "Inventario Final", new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15, new int[] { 5, 5, 5, 5 }, 1); obj.agregaCelda(tDetalles, letraNueveBold, Color.lightGray, "Piezas Degustadas", new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15, new int[] { 5, 5, 5, 5 }, 1); /*FIN DE CABECERA*/ Degustacion[] degustacionDtos = new Degustacion[0]; try { degustacionDtos = this.findDegustaciones(this.degustacion.getIdDegustacion(), this.degustacion.getIdEmpresa(), -1, -1, ""); } catch (Exception e) { } //Listado de Productos for (Degustacion item : degustacionDtos) { if (item != null) { Concepto conceptoDto = null; try { ConceptoBO conceptoBO = new ConceptoBO(item.getIdConcepto(), this.conn); conceptoDto = conceptoBO.getConcepto(); } catch (Exception e) { } //Producto obj.agregaCelda(tDetalles, letraOcho, null, conceptoDto.getNombreDesencriptado(), new boolean[] { true, true, true, true }, Element.ALIGN_JUSTIFIED, Element.ALIGN_TOP, 15, new int[] { 5, 5, 5, 5 }, 1); //Inicio obj.agregaCelda(tDetalles, letraOcho, null, hora.format(item.getFechaApertura()), new boolean[] { true, true, true, true }, Element.ALIGN_JUSTIFIED, Element.ALIGN_TOP, 15, new int[] { 5, 5, 5, 5 }, 1); //Termino obj.agregaCelda(tDetalles, letraOcho, null, hora.format(item.getFechaCierre()), new boolean[] { true, true, true, true }, Element.ALIGN_RIGHT, Element.ALIGN_TOP, 15, new int[] { 5, 5, 5, 5 }, 1); //Inv inicial obj.agregaCelda(tDetalles, letraOcho, null, "" + (item.getCantidad()), new boolean[] { true, true, true, true }, Element.ALIGN_RIGHT, Element.ALIGN_TOP, 15, new int[] { 5, 5, 5, 5 }, 1); //inv final obj.agregaCelda(tDetalles, letraOcho, null, "" + (item.getCantidadCierre()), new boolean[] { true, true, true, true }, Element.ALIGN_RIGHT, Element.ALIGN_TOP, 15, new int[] { 5, 5, 5, 5 }, 1); //Piezas obj.agregaCelda(tDetalles, letraOcho, null, "" + (item.getCantidad() - item.getCantidadCierre()), new boolean[] { true, true, true, true }, Element.ALIGN_RIGHT, Element.ALIGN_TOP, 15, new int[] { 5, 5, 5, 5 }, 1); } } obj.agregaTabla(mainTable, tDetalles, new boolean[] { false, false, false, false }, Element.ALIGN_CENTER, Element.ALIGN_TOP, 0, new int[0], 1); //DOBLE SALTO DE L?NEA obj.agregaCelda(mainTable, letraOcho, null, " ", new boolean[] { false, false, false, false }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0, new int[0], 1); obj.agregaCelda(mainTable, letraOcho, null, " ", new boolean[] { false, false, false, false }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0, new int[0], 1); /*prods Vendidos durante degustacion*/ PdfPTable tVenta = new PdfPTable(4); tVenta.setTotalWidth(550); tVenta.setWidths(new int[] { 70, 140, 170, 120 }); tVenta.setLockedWidth(true); obj.agregaCelda(tVenta, letraNueveBold, Color.lightGray, "Producto Vendido durante Degutacin", new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15, new int[] { 5, 5, 5, 5 }, 4); Productosvendidos[] pedidoProductoDto = new Productosvendidos[0]; String filtroBusqueda = " ID_PEDIDO IN ( SELECT ID_PEDIDO FROM sgfens_pedido WHERE ID_EMPRESA = '" + this.degustacion.getIdEmpresa() + "' AND ID_TIPO_PEDIDO = 2 AND ID_USUARIO_VENDEDOR = " + this.degustacion.getIdUsuario() + " AND " + " ID_ESTATUS_PEDIDO<>2 AND FECHA_PEDIDO BETWEEN '" + this.degustacion.getFechaApertura() + "' AND '" + this.degustacion.getFechaCierre() + "') "; try { pedidoProductoDto = new ProductosvendidosDaoImpl().findByDynamicWhere(filtroBusqueda, null); } catch (Exception e) { } if (pedidoProductoDto.length > 0) { obj.agregaCelda(tVenta, letraOchoBold, null, "Cdigo", new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15, new int[] { 5, 5, 5, 5 }, 1); obj.agregaCelda(tVenta, letraOchoBold, null, "Nombre", new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15, new int[] { 5, 5, 5, 5 }, 1); obj.agregaCelda(tVenta, letraOchoBold, null, "Descripcin", new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15, new int[] { 5, 5, 5, 5 }, 1); obj.agregaCelda(tVenta, letraOchoBold, null, "Unidades Vendidas", new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15, new int[] { 5, 5, 5, 5 }, 1); for (Productosvendidos pedidoProd : pedidoProductoDto) { if (pedidoProd != null) { Concepto conceptoDto = null; try { ConceptoBO conceptoBO = new ConceptoBO(pedidoProd.getIdConcepto(), this.conn); conceptoDto = conceptoBO.getConcepto(); } catch (Exception e) { } //Cdigo obj.agregaCelda(tVenta, letraOcho, null, conceptoDto.getIdentificacion(), new boolean[] { true, true, true, true }, Element.ALIGN_JUSTIFIED, Element.ALIGN_TOP, 15, new int[] { 5, 5, 5, 5 }, 1); //Nombre obj.agregaCelda(tVenta, letraOcho, null, conceptoDto.getNombreDesencriptado(), new boolean[] { true, true, true, true }, Element.ALIGN_JUSTIFIED, Element.ALIGN_TOP, 15, new int[] { 5, 5, 5, 5 }, 1); //Descripcin obj.agregaCelda(tVenta, letraOcho, null, conceptoDto.getDescripcion(), new boolean[] { true, true, true, true }, Element.ALIGN_RIGHT, Element.ALIGN_TOP, 15, new int[] { 5, 5, 5, 5 }, 1); //Unidades Vendidas obj.agregaCelda(tVenta, letraOcho, null, "" + (pedidoProd.getCantidad()), new boolean[] { true, true, true, true }, Element.ALIGN_RIGHT, Element.ALIGN_TOP, 15, new int[] { 5, 5, 5, 5 }, 1); } } } else { obj.agregaCelda(tVenta, letraOcho, null, "No se registrarn datos.", new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15, new int[] { 5, 5, 5, 5 }, 4); } obj.agregaTabla(mainTable, tVenta, new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_TOP, 0, new int[0], 1); //DOBLE SALTO DE L?NEA obj.agregaCelda(mainTable, letraOcho, null, " ", new boolean[] { false, false, false, false }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0, new int[0], 1); obj.agregaCelda(mainTable, letraOcho, null, " ", new boolean[] { false, false, false, false }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0, new int[0], 1); /*Comentarios Adicionales*/ PdfPTable tComenst = new PdfPTable(1); tComenst.setTotalWidth(550); tComenst.setWidths(new int[] { 550 }); tComenst.setLockedWidth(true); obj.agregaCelda(tComenst, letraNueveBold, Color.lightGray, "Comentarios", new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15, new int[] { 5, 5, 5, 5 }, 2); obj.agregaCelda(tComenst, letraOcho, null, this.degustacion.getComentariosCierre(), new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15, new int[] { 5, 5, 5, 5 }, 2); obj.agregaTabla(mainTable, tComenst, new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_TOP, 0, new int[0], 1); //FIN DE CONTENIDO -------- //Aadimos tabla principal construida al documento doc.add(mainTable); mainTable.flushContent(); } catch (Exception ex) { msgError = "No se ha podido generar la representacin impresa de la Degustacion en formato PDF:<br/>" + ex.toString(); } finally { if (doc.isOpen()) doc.close(); } if (!msgError.equals("")) { throw new Exception(msgError); } return baos; }
From source file:de.dhbw.humbuch.util.PDFHandler.java
/** * Use the configuration information to fill the table cells * @param tableBuilder Table configuration *///from w w w. j a v a 2 s. c om private static void fillTableWithContent(TableBuilder tableBuilder) { PdfPCell cell = null; for (int i = 0; i < tableBuilder.contentArray.length; i++) { if (tableBuilder.contentArray[i] == null || tableBuilder.contentArray[i].equals("null")) { tableBuilder.contentArray[i] = ""; } if (tableBuilder.font != null) { cell = new PdfPCell(new Phrase(tableBuilder.contentArray[i], tableBuilder.font)); } else { cell = new PdfPCell(new Phrase(tableBuilder.contentArray[i])); } if (tableBuilder.isAlignedCentrally) { cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); } if (!tableBuilder.withBorder) { cell.setBorder(0); } if (tableBuilder.padding != 0f) { cell.setPadding(tableBuilder.padding); } if (tableBuilder.leading != 0f) { cell.setLeading(tableBuilder.leading, tableBuilder.leading); } tableBuilder.table.addCell(cell); } }
From source file:de.jdufner.sudoku.generator.pdf.PdfCellHandler.java
License:Open Source License
private void formatZelle(final int zeile, final int spalte, final PdfPCell cell) { cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBorderColor(new Color(// Integer.parseInt(getPdfStyle().getProperty("sudoku.board.border.color.red")), // Integer.parseInt(getPdfStyle().getProperty("sudoku.board.border.color.green")), // Integer.parseInt(getPdfStyle().getProperty("sudoku.board.border.color.blue")))); if (isEvenBlockIndex(zeile, spalte)) { cell.setBackgroundColor(new Color(// Integer.parseInt(getPdfStyle().getProperty("sudoku.board.background.odd.color.red")), // Integer.parseInt(getPdfStyle().getProperty("sudoku.board.background.odd.color.green")), // Integer.parseInt(getPdfStyle().getProperty("sudoku.board.background.odd.color.blue")))); } else {/*from w w w .j a v a 2 s . c o m*/ cell.setBackgroundColor(new Color(// Integer.parseInt(getPdfStyle().getProperty("sudoku.board.background.even.color.red")), // Integer.parseInt(getPdfStyle().getProperty("sudoku.board.background.even.color.green")), // Integer.parseInt(getPdfStyle().getProperty("sudoku.board.background.even.color.blue")))); } cell.setBorderWidth(PdfConstants.RAHMEN_DUENN); if (BoxUtils.isFirstRowInBlock(zeile, getSudokuSize())) { cell.setBorderWidthTop(PdfConstants.RAHMEN_DICK); } else { cell.setBorderWidthTop(PdfConstants.RAHMEN_DUENN); } if (BoxUtils.isLastColumnInRow(spalte, getSudokuSize())) { cell.setBorderWidthRight(PdfConstants.RAHMEN_DICK); } else { cell.setBorderWidthRight(PdfConstants.RAHMEN_DUENN); } if (BoxUtils.isLastRowInColumn(zeile, getSudokuSize())) { cell.setBorderWidthBottom(PdfConstants.RAHMEN_DICK); } else { cell.setBorderWidthBottom(PdfConstants.RAHMEN_DUENN); } if (BoxUtils.isFirstColumnInBlock(spalte, getSudokuSize())) { cell.setBorderWidthLeft(PdfConstants.RAHMEN_DICK); } else { cell.setBorderWidthLeft(PdfConstants.RAHMEN_DUENN); } cell.setFixedHeight(27f); }
From source file:de.jdufner.sudoku.generator.pdf.PdfCellHandler.java
License:Open Source License
/** * /*from w w w . j a v a 2s .c om*/ * @return 3x3 Tabelle gefllt mit Kandidaten 1-9 */ private PdfPTable buildCandidates() { final float CANDIDATE_FONT_SIZE = 6f; final float CANDIDATE_PADDING = 1f; PdfPTable candidates = new PdfPTable(3); PdfPCell[][] candidate = new PdfPCell[3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { Paragraph p = new Paragraph(String.valueOf(i * 3 + j + 1)); p.getFont().setSize(CANDIDATE_FONT_SIZE); candidate[i][j] = new PdfPCell(p); candidate[i][j].setPadding(CANDIDATE_PADDING); candidate[i][j].setHorizontalAlignment(Element.ALIGN_CENTER); candidate[i][j].setVerticalAlignment(Element.ALIGN_MIDDLE); candidate[i][j].setBorderColor(new Color(PdfConstants.RAHMEN_FARBE[0], PdfConstants.RAHMEN_FARBE[1], PdfConstants.RAHMEN_FARBE[2])); candidate[i][j].setBorderWidth(PdfConstants.RAHMEN_KEIN); if (i > 0) { candidate[i][j].setBorderWidthTop(PdfConstants.RAHMEN_DUENN); } if (j > 0) { candidate[i][j].setBorderWidthLeft(PdfConstants.RAHMEN_DUENN); } candidates.addCell(candidate[i][j]); } } return candidates; }
From source file:de.jdufner.sudoku.generator.pdf.PdfPrinterImpl.java
License:Open Source License
private PdfPCell buildHeaderCell(String text, int rotation, boolean first, boolean last) { PdfPCell cell = new PdfPCell(new Phrase(text)); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); setBorder(cell, first, last);/*w ww.j a va 2 s .co m*/ cell.setRotation(rotation); return cell; }
From source file:fr.opensagres.odfdom.converter.pdf.internal.StyleEngineForIText.java
License:Open Source License
@Override public void visit(StyleTableCellPropertiesElement ele) { StyleTableCellProperties tableCellProperties = currentStyle.getTableCellProperties(); if (tableCellProperties == null) { tableCellProperties = new StyleTableCellProperties(); currentStyle.setTableCellProperties(tableCellProperties); }/*from w w w .j a va 2s. c om*/ // background-color String backgroundColor = ele.getFoBackgroundColorAttribute(); if (StringUtils.isNotEmpty(backgroundColor)) { tableCellProperties.setBackgroundColor(ColorRegistry.getInstance().getColor(backgroundColor)); } // border String border = ele.getFoBorderAttribute(); if (StringUtils.isNotEmpty(border)) { tableCellProperties.setBorder(new StyleBorder(border, BorderType.ALL)); } // border-bottom String borderBottom = ele.getFoBorderBottomAttribute(); if (StringUtils.isNotEmpty(borderBottom)) { tableCellProperties.setBorderBottom(new StyleBorder(borderBottom, BorderType.BOTTOM)); } // border-left String borderLeft = ele.getFoBorderLeftAttribute(); if (StringUtils.isNotEmpty(borderLeft)) { tableCellProperties.setBorderLeft(new StyleBorder(borderLeft, BorderType.LEFT)); } // border-bottom String borderRight = ele.getFoBorderRightAttribute(); if (StringUtils.isNotEmpty(borderRight)) { tableCellProperties.setBorderRight(new StyleBorder(borderRight, BorderType.RIGHT)); } // border-top String borderTop = ele.getFoBorderTopAttribute(); if (StringUtils.isNotEmpty(borderTop)) { tableCellProperties.setBorderTop(new StyleBorder(borderTop, BorderType.TOP)); } // padding String padding = ele.getFoPaddingAttribute(); if (StringUtils.isNotEmpty(padding)) { tableCellProperties.setPadding(ODFUtils.getDimensionAsPoint(padding)); } // padding-bottom String paddingBottom = ele.getFoPaddingBottomAttribute(); if (StringUtils.isNotEmpty(paddingBottom)) { tableCellProperties.setPaddingBottom(ODFUtils.getDimensionAsPoint(paddingBottom)); } // padding-left String paddingLeft = ele.getFoPaddingLeftAttribute(); if (StringUtils.isNotEmpty(paddingLeft)) { tableCellProperties.setPaddingLeft(ODFUtils.getDimensionAsPoint(paddingLeft)); } // padding-right String paddingRight = ele.getFoPaddingRightAttribute(); if (StringUtils.isNotEmpty(paddingRight)) { tableCellProperties.setPaddingRight(ODFUtils.getDimensionAsPoint(paddingRight)); } // padding-top String paddingTop = ele.getFoPaddingTopAttribute(); if (StringUtils.isNotEmpty(paddingTop)) { tableCellProperties.setPaddingTop(ODFUtils.getDimensionAsPoint(paddingTop)); } // vertical-align String verticalAlign = ele.getStyleVerticalAlignAttribute(); if (StringUtils.isNotEmpty(verticalAlign)) { if (StyleVerticalAlignAttribute.Value.BASELINE.toString().equals(verticalAlign)) { tableCellProperties.setVerticalAlignment(Element.ALIGN_BASELINE); } else if (StyleVerticalAlignAttribute.Value.TOP.toString().equals(verticalAlign)) { tableCellProperties.setVerticalAlignment(Element.ALIGN_TOP); } else if (StyleVerticalAlignAttribute.Value.MIDDLE.toString().equals(verticalAlign)) { tableCellProperties.setVerticalAlignment(Element.ALIGN_MIDDLE); } else if (StyleVerticalAlignAttribute.Value.BOTTOM.toString().equals(verticalAlign)) { tableCellProperties.setVerticalAlignment(Element.ALIGN_BOTTOM); } } super.visit(ele); }
From source file:fr.opensagres.poi.xwpf.converter.pdf.internal.PdfMapper.java
License:Open Source License
@Override protected IITextContainer startVisitTableCell(final XWPFTableCell cell, IITextContainer pdfTableContainer, boolean firstRow, boolean lastRow, boolean firstCol, boolean lastCol, List<XWPFTableCell> vMergeCells) throws Exception { XWPFTableRow row = cell.getTableRow(); XWPFTable table = row.getTable();//from ww w . j a v a 2s .c o m // 1) store table cell info stylesDocument.getTableInfo(table).addCellInfo(cell, firstRow, lastRow, firstCol, lastCol); // 2) create PDF cell StylableTable pdfPTable = (StylableTable) pdfTableContainer; StylableTableCell pdfPCell = pdfDocument.createTableCell(pdfPTable); // pdfPCell.setUseAscender( true ); // pdfPCell.setUseDescender( true ); XWPFTableCell lastVMergedCell = null; if (vMergeCells != null) { pdfPCell.setRowspan(vMergeCells.size()); lastVMergedCell = vMergeCells.get(vMergeCells.size() - 1); stylesDocument.getTableInfo(table).addCellInfo(lastVMergedCell, false, lastRow, firstCol, lastCol); } // border-top TableCellBorder borderTop = stylesDocument.getTableCellBorderWithConflicts(cell, BorderSide.TOP); if (borderTop != null) { boolean borderTopInside = stylesDocument.isBorderInside(cell, BorderSide.TOP); if (borderTopInside) { // Manage conflict border with the adjacent border bottom } } pdfPCell.setBorderTop(borderTop, false); // border-bottom XWPFTableCell theCell = lastVMergedCell != null ? lastVMergedCell : cell; TableCellBorder borderBottom = stylesDocument.getTableCellBorderWithConflicts(theCell, BorderSide.BOTTOM); pdfPCell.setBorderBottom(borderBottom, stylesDocument.isBorderInside(theCell, BorderSide.BOTTOM)); // border-left TableCellBorder borderLeft = stylesDocument.getTableCellBorderWithConflicts(cell, BorderSide.LEFT); pdfPCell.setBorderLeft(borderLeft, stylesDocument.isBorderInside(cell, BorderSide.LEFT)); // border-right TableCellBorder borderRight = stylesDocument.getTableCellBorderWithConflicts(cell, BorderSide.RIGHT); pdfPCell.setBorderRight(borderRight, stylesDocument.isBorderInside(cell, BorderSide.RIGHT)); // Text direction <w:textDirection CTTextDirection direction = stylesDocument.getTextDirection(cell); if (direction != null) { int dir = direction.getVal().intValue(); switch (dir) { case STTextDirection.INT_BT_LR: pdfPCell.setRotation(90); break; case STTextDirection.INT_TB_RL: pdfPCell.setRotation(270); break; } } // Colspan BigInteger gridSpan = stylesDocument.getTableCellGridSpan(cell); if (gridSpan != null) { pdfPCell.setColspan(gridSpan.intValue()); } // Background Color Color backgroundColor = stylesDocument.getTableCellBackgroundColor(cell); if (backgroundColor != null) { pdfPCell.setBackgroundColor(Converter.toAwtColor(backgroundColor)); } // Vertical aligment Enum jc = stylesDocument.getTableCellVerticalAlignment(cell); if (jc != null) { switch (jc.intValue()) { case STVerticalJc.INT_BOTTOM: pdfPCell.setVerticalAlignment(Element.ALIGN_BOTTOM); break; case STVerticalJc.INT_CENTER: pdfPCell.setVerticalAlignment(Element.ALIGN_MIDDLE); break; case STVerticalJc.INT_TOP: pdfPCell.setVerticalAlignment(Element.ALIGN_TOP); break; } } // Cell margin Float marginTop = stylesDocument.getTableCellMarginTop(cell); if (marginTop == null) { marginTop = stylesDocument.getTableRowMarginTop(row); if (marginTop == null) { marginTop = stylesDocument.getTableMarginTop(table); } } if (marginTop != null) { pdfPCell.setPaddingTop(marginTop); } Float marginBottom = stylesDocument.getTableCellMarginBottom(cell); if (marginBottom == null) { marginBottom = stylesDocument.getTableRowMarginBottom(row); if (marginBottom == null) { marginBottom = stylesDocument.getTableMarginBottom(table); } } if (marginBottom != null && marginBottom > 0) { pdfPCell.setPaddingBottom(marginBottom); } Float marginLeft = stylesDocument.getTableCellMarginLeft(cell); if (marginLeft == null) { marginLeft = stylesDocument.getTableRowMarginLeft(row); if (marginLeft == null) { marginLeft = stylesDocument.getTableMarginLeft(table); } } if (marginLeft != null) { pdfPCell.setPaddingLeft(marginLeft); } Float marginRight = stylesDocument.getTableCellMarginRight(cell); if (marginRight == null) { marginRight = stylesDocument.getTableRowMarginRight(row); if (marginRight == null) { marginRight = stylesDocument.getTableMarginRight(table); } } if (marginRight != null) { pdfPCell.setPaddingRight(marginRight); } // Row height TableHeight tableHeight = stylesDocument.getTableRowHeight(row); if (tableHeight != null) { if (tableHeight.minimum) { pdfPCell.setMinimumHeight(tableHeight.height); } else { pdfPCell.setFixedHeight(tableHeight.height); } } // No wrap Boolean noWrap = stylesDocument.getTableCellNoWrap(cell); if (noWrap != null) { pdfPCell.setNoWrap(noWrap); } return pdfPCell; }
From source file:fr.opensagres.xdocreport.itext.extension.SimpleTable.java
License:Open Source License
public static void main(String[] args) { Document document = new Document(PageSize.A4.rotate(), 10, 10, 10, 10); try {// ww w . j a v a 2 s. co m PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("SimpleTable.pdf")); document.open(); PdfPTable table = new PdfPTable(2); PdfPCell cell; Paragraph p = new Paragraph("Text Text Text "); table.addCell("cell"); table.addCell(p); table.addCell("cell"); cell = new PdfPCell(p); p = new Paragraph("Text Text Text "); //Chunk c = new Chunk( "zzzzzzzzzz" ); //cell.setPadding( 0f ); //cell.getColumn().setAdjustFirstLine( false ); // make a room for borders //cell.setUseBorderPadding( false ); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(Color.red); cell.addElement(p); cell.setUseAscender(true); //cell.addElement(c ); // cell.setPaddingTop( 0f ); // cell.setPaddingLeft( 20f ); table.addCell(cell); //table.addCell( "cell" ); document.add(table); } catch (Exception de) { de.printStackTrace(); } document.close(); }