List of usage examples for com.lowagie.text Element ALIGN_LEFT
int ALIGN_LEFT
To view the source code for com.lowagie.text Element ALIGN_LEFT.
Click Source Link
From source file:com.qcadoo.report.api.pdf.PdfPageNumbering.java
License:Open Source License
private void buildFooter(final PdfWriter writer, final Document document) { PdfContentByte cb = writer.getDirectContent(); cb.saveState();//w ww .ja v a 2 s . com String text = footer.getPage() + " " + writer.getPageNumber() + " " + footer.getIn() + " "; float textBase = document.bottom() - 25; float textSize = FontUtils.getDejavu().getWidthPoint(text, 7); cb.setColorFill(ColorUtils.getLightColor()); cb.setColorStroke(ColorUtils.getLightColor()); cb.setLineWidth(1); cb.setLineDash(2, 2, 1); cb.moveTo(document.left(), document.bottom() - 10); cb.lineTo(document.right(), document.bottom() - 10); cb.stroke(); cb.beginText(); cb.setFontAndSize(FontUtils.getDejavu(), 7); float adjust = FontUtils.getDejavu().getWidthPoint("0", 7); cb.setTextMatrix(document.right() - textSize - adjust, textBase); cb.showText(text); textSize = FontUtils.getDejavu().getWidthPoint(footer.getGeneratedBy(), 7); cb.setTextMatrix(document.right() - textSize, textBase - 10); cb.showText(footer.getGeneratedBy()); textSize = FontUtils.getDejavu().getWidthPoint(generationDate, 7); cb.setTextMatrix(document.right() - textSize, textBase - 20); cb.showText(generationDate); cb.endText(); try { textSize = FontUtils.getDejavu().getWidthPoint(footer.getAdditionalText(), 7); ColumnText ct = new ColumnText(cb); ct.setSimpleColumn(new Phrase(footer.getAdditionalText(), FontUtils.getDejavuRegular7Light()), document.left() + 240, textBase + 10, document.left() + 390, textBase - 25, 10, Element.ALIGN_LEFT); ct.go(); } catch (DocumentException e) { LOG.warn("Problem with additional text generation in report footer."); } try { ColumnText ct = new ColumnText(cb); ct.setSimpleColumn(document.left(), textBase + 10, document.left() + 230, textBase - 25, 10, Element.ALIGN_LEFT); ct.addText(new Phrase(footer.getCompanyName() + "\n", FontUtils.getDejavuRegular7Light())); if (!"".equals(footer.getAddress())) { ct.addText(new Phrase(footer.getAddress() + "\n", FontUtils.getDejavuRegular7Light())); } if (!"".equals(footer.getPhoneEmail())) { ct.addText(new Phrase(footer.getPhoneEmail(), FontUtils.getDejavuRegular7Light())); } ct.go(); } catch (DocumentException e) { LOG.warn("Problem with company text generation in report footer."); } cb.addTemplate(total, document.right() - adjust, textBase); cb.restoreState(); }
From source file:com.qcadoo.report.internal.PdfHelperImpl.java
License:Open Source License
@Override public void addDocumentHeader(final Document document, final String name, final String documenTitle, final String documentAuthor, final Date date, final String username) throws DocumentException { SimpleDateFormat df = new SimpleDateFormat(DateUtils.L_DATE_TIME_FORMAT, getLocale()); LineSeparator line = new LineSeparator(3, 100f, ColorUtils.getLineDarkColor(), Element.ALIGN_LEFT, 0); document.add(Chunk.NEWLINE);/* w w w . ja va2 s . c o m*/ Paragraph title = new Paragraph(new Phrase(documenTitle, FontUtils.getDejavuBold17Light())); title.add(new Phrase(" " + name, FontUtils.getDejavuBold17Dark())); title.setSpacingAfter(7f); document.add(title); document.add(line); PdfPTable userAndDate = new PdfPTable(2); userAndDate.setWidthPercentage(100f); userAndDate.setHorizontalAlignment(Element.ALIGN_LEFT); userAndDate.getDefaultCell().setBorderWidth(0); Paragraph userParagraph = new Paragraph(new Phrase(documentAuthor, FontUtils.getDejavuRegular9Light())); userParagraph.add(new Phrase(" " + username, FontUtils.getDejavuRegular9Dark())); Paragraph dateParagraph = new Paragraph(df.format(date), FontUtils.getDejavuRegular9Light()); userAndDate.addCell(userParagraph); userAndDate.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); userAndDate.addCell(dateParagraph); userAndDate.setSpacingAfter(14f); document.add(userAndDate); }
From source file:com.qcadoo.report.internal.PdfHelperImpl.java
License:Open Source License
@Override public void addDocumentHeader(final Document document, final String name, final String documenTitle, final String documentAuthor, final Date date) throws DocumentException { SimpleDateFormat df = new SimpleDateFormat(DateUtils.L_DATE_TIME_FORMAT, getLocale()); LineSeparator line = new LineSeparator(2, 100f, ColorUtils.getLineDarkColor(), Element.ALIGN_LEFT, 0); document.add(Chunk.NEWLINE);//ww w . j av a 2s. c o m Paragraph title = new Paragraph(new Phrase(documenTitle, FontUtils.getDejavuBold17Light())); title.add(new Phrase(" " + name, FontUtils.getDejavuBold17Dark())); title.setSpacingAfter(7f); document.add(title); document.add(line); PdfPTable userAndDate = new PdfPTable(2); userAndDate.setWidthPercentage(100f); userAndDate.setHorizontalAlignment(Element.ALIGN_LEFT); userAndDate.getDefaultCell().setBorderWidth(0); Paragraph userParagraph = new Paragraph(new Phrase(documentAuthor, FontUtils.getDejavuRegular9Light())); userParagraph.add(new Phrase(" " + getDocumentAuthor(), FontUtils.getDejavuRegular9Dark())); Paragraph dateParagraph = new Paragraph(df.format(date), FontUtils.getDejavuRegular9Light()); userAndDate.addCell(userParagraph); userAndDate.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); userAndDate.addCell(dateParagraph); userAndDate.setSpacingAfter(14f); document.add(userAndDate); }
From source file:com.qcadoo.report.internal.PdfHelperImpl.java
License:Open Source License
@Override public void addDocumentHeaderThin(final Document document, final String name, final String documentTitle, final String documentAuthor, final Date date) throws DocumentException { SimpleDateFormat df = new SimpleDateFormat(DateUtils.L_DATE_TIME_FORMAT, getLocale()); LineSeparator line = new LineSeparator(2, 100f, ColorUtils.getLineDarkColor(), Element.ALIGN_LEFT, 0); Paragraph title = new Paragraph(new Phrase(documentTitle, FontUtils.getDejavuBold14Light())); title.add(new Phrase(" " + name, FontUtils.getDejavuBold14Dark())); title.setSpacingAfter(7f);/*w ww . j ava 2 s. co m*/ document.add(title); document.add(line); PdfPTable userAndDate = new PdfPTable(2); userAndDate.setWidthPercentage(100f); userAndDate.setHorizontalAlignment(Element.ALIGN_LEFT); userAndDate.getDefaultCell().setBorderWidth(0); Paragraph userParagraph = new Paragraph(new Phrase(documentAuthor, FontUtils.getDejavuRegular9Light())); userParagraph.add(new Phrase(" " + getDocumentAuthor(), FontUtils.getDejavuRegular9Dark())); Paragraph dateParagraph = new Paragraph(df.format(date), FontUtils.getDejavuRegular9Light()); userAndDate.addCell(userParagraph); userAndDate.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); userAndDate.addCell(dateParagraph); userAndDate.setSpacingAfter(10f); document.add(userAndDate); }
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 av a2 s .c om*/ 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.stratelia.webactiv.kmelia.control.Callback.java
License:Open Source License
@Override public void handleStartTag(Tag t, MutableAttributeSet a, int pos) throws KmeliaRuntimeException { SilverTrace.info("kmelia", "Callback.handleStartTag", "root.MSG_ENTRY_METHOD", "t = " + t.toString()); if (TABLE.equals(t)) { try {/*from w ww.j a v a 2 s. c o m*/ tbl = new Table(Integer.parseInt(columns.get(++current_table))); tbl.setBorderWidth(0); tbl.setAlignment(Element.ALIGN_LEFT); attribute = a.getAttribute(Attribute.WIDTH); if (attribute != null) { attribute_value = attribute.toString(); if ("%".equals(attribute_value.substring(attribute_value.length() - 1))) { tbl.setWidth( (Integer.parseInt(attribute_value.substring(0, attribute_value.length() - 1)))); } } attribute = a.getAttribute(Attribute.CELLPADDING); if (attribute != null) { attribute_value = attribute.toString(); tbl.setSpacing(Integer.parseInt(attribute_value)); } attribute = a.getAttribute(Attribute.CELLSPACING); if (attribute != null) { attribute_value = attribute.toString(); tbl.setPadding(Integer.parseInt(attribute_value)); } } catch (Exception ex) { throw new KmeliaRuntimeException("Callback.handleStartTag", SilverpeasRuntimeException.WARNING, "kmelia.EX_CANNOT_SHOW_PDF_GENERATION", ex); } } else if (TD.equals(t)) { try { if (cl == null) { cl = new Cell(); cl.setBorderWidth(0); } is_was_text = false; } catch (Exception ex) { throw new KmeliaRuntimeException("Callback.handleStartTag", SilverpeasRuntimeException.WARNING, "kmelia.EX_CANNOT_SHOW_PDF_GENERATION", ex); } } else if (H1.equals(t)) { font_size = Font.DEFAULTSIZE + 1; } else if (H2.equals(t)) { font_size = Font.DEFAULTSIZE + 2; } else if (H3.equals(t)) { font_size = Font.DEFAULTSIZE + 3; } else if (H4.equals(t)) { font_size = Font.DEFAULTSIZE + 4; } else if (H5.equals(t)) { font_size = Font.DEFAULTSIZE + 5; } else if (H6.equals(t)) { font_size = Font.DEFAULTSIZE + 6; } else if (FONT.equals(t)) { attribute = a.getAttribute(Attribute.SIZE); if (attribute != null) { font_size = Integer.parseInt(attribute.toString()) + Font.DEFAULTSIZE - 1; } } else if (t.equals(B)) { font_properties = font_properties | Font.BOLD; } else if (t.equals(I)) { font_properties = font_properties | Font.ITALIC; } else if (t.equals(U)) { // current PDF package doesn't support it } }
From source file:com.tsp.gespro.bo.DegustacionBO.java
/** * Representacin impresa PDF// w w w. j a v a 2s .c o 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:corner.orm.tapestry.jasper.exporter.CornerPdfExporter.java
License:Apache License
/** * ?.????./* ww w . ja va 2 s . c o m*/ * <p>:ColumnText?, * ?NO_MORE_COLUMN???,TextField??. * TextField?. * @see net.sf.jasperreports.engine.export.JRPdfExporter#exportText(net.sf.jasperreports.engine.JRPrintText) */ @Override protected void exportText(JRPrintText text) throws DocumentException { JRStyledText styledText = getStyledText(text, false); if (styledText == null) { return; } int textLength = styledText.length(); int x = text.getX() + getOffsetX(); int y = text.getY() + getOffsetY(); int width = text.getWidth(); int height = text.getHeight(); int topPadding = text.getTopPadding(); int leftPadding = text.getLeftPadding(); int bottomPadding = text.getBottomPadding(); int rightPadding = text.getRightPadding(); int xFillCorrection = 0; int yFillCorrection = 0; double angle = 0; switch (text.getRotation()) { case JRTextElement.ROTATION_LEFT: { y = text.getY() + getOffsetY() + text.getHeight(); xFillCorrection = 1; width = text.getHeight(); height = text.getWidth(); int tmpPadding = topPadding; topPadding = leftPadding; leftPadding = bottomPadding; bottomPadding = rightPadding; rightPadding = tmpPadding; angle = Math.PI / 2; break; } case JRTextElement.ROTATION_RIGHT: { x = text.getX() + getOffsetX() + text.getWidth(); yFillCorrection = -1; width = text.getHeight(); height = text.getWidth(); int tmpPadding = topPadding; topPadding = rightPadding; rightPadding = bottomPadding; bottomPadding = leftPadding; leftPadding = tmpPadding; angle = -Math.PI / 2; break; } case JRTextElement.ROTATION_UPSIDE_DOWN: { x = text.getX() + getOffsetX() + text.getWidth(); y = text.getY() + getOffsetY() + text.getHeight(); int tmpPadding = topPadding; topPadding = bottomPadding; bottomPadding = tmpPadding; tmpPadding = leftPadding; leftPadding = rightPadding; rightPadding = tmpPadding; angle = Math.PI; break; } case JRTextElement.ROTATION_NONE: default: { } } AffineTransform atrans = new AffineTransform(); atrans.rotate(angle, x, jasperPrint.getPageHeight() - y); pdfContentByte.transform(atrans); if (text.getMode() == JRElement.MODE_OPAQUE) { Color backcolor = text.getBackcolor(); pdfContentByte.setRGBColorStroke(backcolor.getRed(), backcolor.getGreen(), backcolor.getBlue()); pdfContentByte.setRGBColorFill(backcolor.getRed(), backcolor.getGreen(), backcolor.getBlue()); pdfContentByte.setLineWidth(1f); pdfContentByte.setLineDash(0f); pdfContentByte.rectangle(x + xFillCorrection, jasperPrint.getPageHeight() - y + yFillCorrection, width - 1, -height + 1); pdfContentByte.fillStroke(); } else { /* * pdfContentByte.setRGBColorStroke( text.getForecolor().getRed(), * text.getForecolor().getGreen(), text.getForecolor().getBlue() ); * pdfContentByte.setLineWidth(0.1f); * pdfContentByte.setLineDash(0f); pdfContentByte.rectangle( * text.getX() + offsetX, jasperPrint.getPageHeight() - text.getY() - * offsetY, text.getWidth(), - text.getHeight() ); * pdfContentByte.stroke(); */ } if (textLength > 0) { int horizontalAlignment = Element.ALIGN_LEFT; switch (text.getHorizontalAlignment()) { case JRAlignment.HORIZONTAL_ALIGN_LEFT: { if (text.getRunDirection() == JRPrintText.RUN_DIRECTION_LTR) { horizontalAlignment = Element.ALIGN_LEFT; } else { horizontalAlignment = Element.ALIGN_RIGHT; } break; } case JRAlignment.HORIZONTAL_ALIGN_CENTER: { horizontalAlignment = Element.ALIGN_CENTER; break; } case JRAlignment.HORIZONTAL_ALIGN_RIGHT: { if (text.getRunDirection() == JRPrintText.RUN_DIRECTION_LTR) { horizontalAlignment = Element.ALIGN_RIGHT; } else { horizontalAlignment = Element.ALIGN_LEFT; } break; } case JRAlignment.HORIZONTAL_ALIGN_JUSTIFIED: { horizontalAlignment = Element.ALIGN_JUSTIFIED; break; } default: { horizontalAlignment = Element.ALIGN_LEFT; } } float verticalOffset = 0f; switch (text.getVerticalAlignment()) { case JRAlignment.VERTICAL_ALIGN_TOP: { verticalOffset = 0f; break; } case JRAlignment.VERTICAL_ALIGN_MIDDLE: { verticalOffset = (height - topPadding - bottomPadding - text.getTextHeight()) / 2f; break; } case JRAlignment.VERTICAL_ALIGN_BOTTOM: { verticalOffset = height - topPadding - bottomPadding - text.getTextHeight(); break; } default: { verticalOffset = 0f; } } float llx = x + leftPadding; float lly = jasperPrint.getPageHeight() - y - topPadding - verticalOffset - text.getLeadingOffset(); float urx = x + width - rightPadding; float ury = jasperPrint.getPageHeight() - y - height + bottomPadding; //?,??? if (this.jasperMoveXY != null) { llx = x + leftPadding + jasperMoveXY.getX(); lly = jasperPrint.getPageHeight() - y - topPadding - verticalOffset - text.getLeadingOffset() - jasperMoveXY.getY(); urx = x + width - rightPadding + jasperMoveXY.getX(); ury = jasperPrint.getPageHeight() - y - height + bottomPadding - jasperMoveXY.getY(); } boolean isOver = false; int status = ColumnText.START_COLUMN; Phrase phrase = getPhrase(styledText, text); ColumnText colText = new ColumnText(pdfContentByte); colText.setSimpleColumn(phrase, llx, lly, urx, ury, 0, // text.getLineSpacingFactor(),// // * // text.getFont().getSize(), horizontalAlignment); colText.setLeading(0, text.getLineSpacingFactor());// * // text.getFont().getSize()); colText.setRunDirection( text.getRunDirection() == JRPrintText.RUN_DIRECTION_LTR ? PdfWriter.RUN_DIRECTION_LTR : PdfWriter.RUN_DIRECTION_RTL); float yLine = colText.getYLine(); // ColumnText while (colText.hasMoreText(status)) { status = colText.go(true); colText.setYLine(yLine); // ??,true if (status == ColumnText.NO_MORE_COLUMN) { isOver = true; break; } } // ,ColumnText if (!isOver) { colText.setText(phrase); status = ColumnText.START_COLUMN; while (colText.hasMoreText(status)) { status = colText.go(); colText.setYLine(yLine); } } else { // TextField,?? String key = text.getKey();// PdfTextid if (alreadyExistFields.contains(key)) { // ? key = createUniqueName(); } alreadyExistFields.add(key); TextField tf = new TextField(pdfContentByte.getPdfWriter(), new Rectangle(llx, lly, urx, ury), key); tf.setAlignment(horizontalAlignment); tf.setText(text.getText()); tf.setFont(PdfUtils.createSongLightBaseFont()); // styledText ??,? if (!text.isStyledText()) { tf.setOptions(TextField.MULTILINE); } try { pdfContentByte.getPdfWriter().addAnnotation(tf.getTextField()); } catch (IOException e) { e.printStackTrace(); } } } atrans = new AffineTransform(); atrans.rotate(-angle, x, jasperPrint.getPageHeight() - y); pdfContentByte.transform(atrans); /* */ exportBox(text, text); }
From source file:Cotizacion.ExportarPDF.java
private static void acomodarDatosEspecificaciones(Paragraph datosNormal) throws BadElementException { Connection conexion = null;// w w w . j a v a2 s . co m try { Class.forName("org.gjt.mm.mysql.Driver"); conexion = (Connection) DriverManager.getConnection(url, login, password); stm = (Statement) conexion.createStatement(); ResultSet rs = stm.executeQuery("select max(numero) as numero from todolonas.cotizacion;"); while (rs.next()) { idCotiza = rs.getInt("numero"); } conexion.close(); } catch (Exception e) { System.out.println("error: " + e); } try { Class.forName("org.gjt.mm.mysql.Driver"); conexion = (Connection) DriverManager.getConnection(url, login, password); stm = (Statement) conexion.createStatement(); ResultSet rs = stm.executeQuery( "SELECT especificacionTrabajo FROM todolonas.cotizacion where numero = '" + idCotiza + "';"); while (rs.next()) { especificacionTrabajo = rs.getString("especificacionTrabajo"); } conexion.close(); } catch (Exception e) { System.out.println("error: " + e); } if (especificacionTrabajo.equals("NA")) { System.out.println("no hay especificacion trabajo"); } else { PdfPTable table2 = new PdfPTable(2); table2.getDefaultCell().setBorder(PdfPCell.NO_BORDER); table2.addCell("Especificacin Trabajo"); table2.addCell(especificacionTrabajo); table2.setWidthPercentage(70); table2.setHorizontalAlignment(Element.ALIGN_LEFT); agregarLineasEnBlanco(datosNormal, 1); datosNormal.add(table2); } try { Class.forName("org.gjt.mm.mysql.Driver"); conexion = (Connection) DriverManager.getConnection(url, login, password); stm = (Statement) conexion.createStatement(); // System.out.println("nombre++++----> "+nombreCliente); ResultSet rs = stm.executeQuery( "SELECT especificacionDiseno FROM todolonas.cotizacion where numero = '" + idCotiza + "';"); while (rs.next()) { especificacionDiseno = rs.getString("especificacionDiseno"); } conexion.close(); } catch (Exception e) { System.out.println("error: " + e); } if (especificacionDiseno.equals("NA")) { System.out.println("no hay especificacion trabajo"); } else { PdfPTable table2 = new PdfPTable(2); table2.getDefaultCell().setBorder(PdfPCell.NO_BORDER); table2.addCell("Especificacin Diseo"); table2.addCell(especificacionDiseno); table2.setWidthPercentage(70); table2.setHorizontalAlignment(Element.ALIGN_LEFT); agregarLineasEnBlanco(datosNormal, 1); datosNormal.add(table2); } }
From source file:de.jdufner.sudoku.generator.pdf.PdfPrinterImpl.java
License:Open Source License
private PdfPTable writePdfTable(SudokuData sudokuData) { PdfPTable einzelnesSudoku = new PdfPTable(1); PdfPTable ueberschrift = new PdfPTable(2); PdfPCell linkeZelle = new PdfPCell(new Phrase("ID: " + sudokuData.getId())); linkeZelle.getPhrase().getFont().setSize(9f); linkeZelle.setBorder(Integer.parseInt(getPdfStyle().getProperty("border.none"))); linkeZelle.setHorizontalAlignment(Element.ALIGN_LEFT); ueberschrift.addCell(linkeZelle);//w w w. j a v a 2 s . c om PdfPCell rechteZelle = new PdfPCell( new Phrase(Level.valueOf(sudokuData.getLevel()).getName() + " (" + sudokuData.getFixed() + ")")); rechteZelle.getPhrase().getFont().setSize(9f); rechteZelle.setBorder(0); rechteZelle.setHorizontalAlignment(Element.ALIGN_RIGHT); ueberschrift.addCell(rechteZelle); PdfPCell obereZelle = new PdfPCell(ueberschrift); obereZelle.setBorder(0); einzelnesSudoku.addCell(obereZelle); PdfCellHandler pdfCellHandler = new PdfCellHandler(SudokuSize.getByUnitSize(sudokuData.getSize()), getPdfStyle()); pdfCellHandler.initialize(); HandlerUtil.forEachCell(SudokuFactory.INSTANCE.buildSudoku(sudokuData.getSudokuAsString()), pdfCellHandler); PdfPCell untereZelle = new PdfPCell(pdfCellHandler.getTable()); untereZelle.setBorder(0); einzelnesSudoku.addCell(untereZelle); return einzelnesSudoku; }