Example usage for com.itextpdf.text Image setSpacingAfter

List of usage examples for com.itextpdf.text Image setSpacingAfter

Introduction

In this page you can find the example usage for com.itextpdf.text Image setSpacingAfter.

Prototype


public void setSpacingAfter(final float spacing) 

Source Link

Document

Sets the spacing after this image.

Usage

From source file:com.ideationdesignservices.txtbook.pdf.TxtBookPdf.java

public float addConversationPart(ColumnText ct, int column, String dateString, String senderString,
        String contentString, Bitmap contentBitmap, Boolean isVideo, Boolean isMe)
        throws DocumentException, MalformedURLException, IOException {
    float messageWidth = 196.0f;
    Chunk dateChunk = new Chunk(new StringBuilder(String.valueOf(dateString))
            .append(MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR).toString(), this.sansFont6Gray);
    float dateWidth = dateChunk.getWidthPoint();
    Paragraph contentParagraph = new Paragraph();
    if (contentString.length() > 0) {
        Element contentChunk = new Chunk(contentString, this.sansFont9);
        messageWidth = contentChunk.getWidthPoint();
        contentParagraph.add(contentChunk);
    }/*ww w. j a v a  2 s .  co m*/
    if (messageWidth < dateWidth) {
        messageWidth = dateWidth;
    }
    if (messageWidth > MAX_COLUMN_CONTENT_WIDTH) {
        messageWidth = MAX_COLUMN_CONTENT_WIDTH;
        dateWidth += 7.0f;
    }
    Paragraph dateParagraph = new Paragraph(dateChunk);
    if (isMe.booleanValue()) {
        dateParagraph.setAlignment(0);
        dateParagraph
                .setIndentationLeft((((BUBBLE_L_WIDTH + messageWidth) + BUBBLE_R_WIDTH) + 7.0f) - dateWidth);
    } else {
        dateParagraph.setAlignment(2);
        dateParagraph
                .setIndentationRight((((BUBBLE_L_WIDTH + messageWidth) + BUBBLE_R_WIDTH) + 7.0f) - dateWidth);
    }
    ct.addElement(dateParagraph);
    contentParagraph.setExtraParagraphSpace(10.0f);
    if (contentString.length() > 0) {
        contentParagraph.setAlignment(0);
        if (isMe.booleanValue()) {
            contentParagraph.setIndentationLeft(8.6f);
            contentParagraph.setIndentationRight(BUBBLE_TEXT_INDENT_ALTERNATE);
        } else {
            contentParagraph.setIndentationRight(8.6f);
            float indentLeft = COLUMN_WIDTH - (BUBBLE_L_WIDTH + messageWidth);
            if (messageWidth == MAX_COLUMN_CONTENT_WIDTH) {
                indentLeft += BUBBLE_TEXT_INDENT_ALTERNATE;
            }
            contentParagraph.setIndentationLeft(indentLeft);
        }
        ct.addElement(contentParagraph);
    } else if (contentBitmap != null) {
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        if (isVideo.booleanValue()) {
            contentBitmap.compress(CompressFormat.PNG, 50, stream);
        } else {
            contentBitmap.compress(CompressFormat.JPEG, 50, stream);
        }
        Image contentImage = Image.getInstance(stream.toByteArray());
        contentImage.scaleToFit(198.0f, 198.0f);
        if (isVideo.booleanValue()) {
            contentImage.setCompressionLevel(this.settings.compressionLevel);
        }
        contentImage.setSpacingBefore(10.0f);
        contentImage.setSpacingAfter(10.0f);
        if (isMe.booleanValue()) {
            contentImage.setAlignment(1);
        } else {
            contentImage.setAlignment(1);
        }
        ct.addElement(contentImage);
    }
    Paragraph senderParagraph = new Paragraph(new Chunk(senderString, this.sansFont9Gray));
    if (!isMe.booleanValue()) {
        senderParagraph.setAlignment(2);
    }
    senderParagraph.setSpacingAfter(BUBBLE_TEXT_INDENT_ALTERNATE);
    ct.addElement(senderParagraph);
    return messageWidth;
}

From source file:com.masscustsoft.service.ToPdf.java

License:Open Source License

@Override
public Image createImage(String src, final Map<String, String> attrs, final ChainedProperties chain,
        final DocListener document, final ImageProvider img_provider, final HashMap<String, Image> img_store,
        final String img_baseurl) throws DocumentException, IOException {
    Image img = null;
    // getting the image using an image provider
    if (img_provider != null)
        img = img_provider.getImage(src, attrs, chain, document);
    // getting the image from an image store
    if (img == null && img_store != null) {
        Image tim = img_store.get(src);
        if (tim != null)
            img = Image.getInstance(tim);
    }//from  w ww . j a v a 2s .  c  om
    if (img != null)
        return img;
    ////if src start with data: it's dataUri and parse it imme.
    if (src.startsWith("remote?")) {
        BeanFactory bf = BeanFactory.getBeanFactory();
        String pp = src.substring(7);
        String[] ss = pp.split("\\&");
        try {
            String id = "~", fsId = LightUtil.getRepository().getFsId();
            for (String s : ss) {
                String[] sss = s.split("=");
                if (sss[0].equals("id"))
                    id = sss[1];
                if (sss[0].equals("fsId"))
                    fsId = sss[1];
            }
            IRepository fs = bf.getRepository(fsId);

            InputStream is = fs.getResource(id);
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            StreamUtil.copyStream(is, os, 0);
            is.close();
            os.close();
            img = Image.getInstance(os.toByteArray());
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else if (src.startsWith("data:")) {
        int i = src.indexOf(",");
        byte[] bits = Base64.decode(src.substring(i + 1));
        img = Image.getInstance(bits);
    } else {
        ////
        // introducing a base url
        // relative src references only
        if (!src.startsWith("http") && img_baseurl != null) {
            src = img_baseurl + src;
        } else if (img == null && !src.startsWith("http")) {
            String path = chain.getProperty(HtmlTags.IMAGEPATH);
            if (path == null)
                path = "";
            src = new File(path, src).getPath();
        }
        img = Image.getInstance(src);
    }

    if (img == null)
        return null;

    float actualFontSize = HtmlUtilities.parseLength(chain.getProperty(HtmlTags.SIZE),
            HtmlUtilities.DEFAULT_FONT_SIZE);
    if (actualFontSize <= 0f)
        actualFontSize = HtmlUtilities.DEFAULT_FONT_SIZE;
    String width = attrs.get(HtmlTags.WIDTH);
    float widthInPoints = HtmlUtilities.parseLength(width, actualFontSize);
    String height = attrs.get(HtmlTags.HEIGHT);

    float heightInPoints = HtmlUtilities.parseLength(height, actualFontSize);

    if (widthInPoints == 0 && heightInPoints == 0) {
        Document doc = (Document) document;
        widthInPoints = doc.getPageSize().getWidth();
    }

    if (widthInPoints > 0 && heightInPoints > 0) {
        img.scaleAbsolute(widthInPoints, heightInPoints);
    } else if (widthInPoints > 0) {
        heightInPoints = img.getHeight() * widthInPoints / img.getWidth();
        img.scaleAbsolute(widthInPoints, heightInPoints);
    } else if (heightInPoints > 0) {
        widthInPoints = img.getWidth() * heightInPoints / img.getHeight();
        img.scaleAbsolute(widthInPoints, heightInPoints);
    }

    String before = chain.getProperty(HtmlTags.BEFORE);
    if (before != null)
        img.setSpacingBefore(Float.parseFloat(before));
    String after = chain.getProperty(HtmlTags.AFTER);
    if (after != null)
        img.setSpacingAfter(Float.parseFloat(after));
    img.setWidthPercentage(0);
    return img;
}

From source file:Servlets.PDF.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    response.setContentType("application/pdf");
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);

    try {/*from  ww w  .j a  v a2 s.  com*/
        //obtengo datos de cliente,  reserva y total
        String rreserva = request.getParameter("reserva");
        String rcliente = request.getParameter("cliente");
        String rtotal = request.getParameter("total");
        //String rtipo = request.getParameter("esProv");

        // Obtener datos de cliente e items de reserva
        DtUsuario dtu = getDtUsuario(rcliente);
        String nombre = dtu.getNombre();
        String apellido = dtu.getApellido();
        String servicios = "";
        String promos = "";
        java.util.List<DtItemReserva> dtItems = listarItems(Integer.parseInt(rreserva)).getItems();
        Iterator<DtItemReserva> iter = dtItems.iterator();
        DtItemReserva dtItem;

        // Crear y abrir documento

        String HomeDeUSuario = System.getProperty("user.home");

        String ruta = HomeDeUSuario + "/Factura Reserva " + rreserva + ".pdf";

        FileOutputStream archivo = new FileOutputStream(ruta);

        PdfWriter writer = PdfWriter.getInstance(document, archivo);

        document.open();

        Date date = new Date();

        DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
        String fecha = dateFormat.format(date);

        // Agregar marcador inicial

        // Crear y agregar prrafo simple
        Paragraph paragraph1 = new Paragraph();
        Image imagen = Image.getInstance("http://localhost:8084/Help4TravelingWeb/img/logo-icon2.png");
        imagen.scaleAbsolute(200f, 200f);

        imagen.setAbsolutePosition(10, 650);
        imagen.setSpacingAfter(20);
        paragraph1.add(imagen);
        document.add(paragraph1);
        //fecha
        Paragraph fecha1 = new Paragraph(fecha);

        //encabezado
        Paragraph futuros = new Paragraph("Futuros Tecnologos SRL");
        Paragraph rut = new Paragraph("RUT 123456789012");
        Paragraph direccion = new Paragraph(" Av. Gral. Rivera 3629");
        Paragraph telefono = new Paragraph(" Tel: 555-5412");
        Paragraph nombre_empresa = new Paragraph(" Help4Travelling");

        //datos cliente
        String nombrecliente = nombre.toUpperCase() + " " + apellido.toUpperCase();
        String direccioncliente = " ";
        String rutcliente = "consumidor final".toUpperCase();
        Paragraph cliente = new Paragraph("Cliente: " + nombrecliente);
        Paragraph dircliente = new Paragraph("Direccion: " + direccioncliente);
        Paragraph rutcli = new Paragraph("RUT: " + rutcliente);

        //datos boleta

        String factura = rreserva;
        Paragraph tipodoc = new Paragraph("Contado");
        Paragraph Nfac = new Paragraph(" N  " + factura);

        //alineaciones

        //fecha 
        fecha1.setAlignment(Element.ALIGN_RIGHT);

        //encabezado
        futuros.setAlignment(Element.ALIGN_CENTER);
        rut.setAlignment(Element.ALIGN_CENTER);
        direccion.setAlignment(Element.ALIGN_CENTER);
        telefono.setAlignment(Element.ALIGN_CENTER);

        //nombre empresa
        nombre_empresa.setAlignment(Element.ALIGN_LEFT);
        nombre_empresa.setSpacingBefore(10);
        nombre_empresa.setSpacingAfter(30);

        //datos de boleta
        tipodoc.setAlignment(Element.ALIGN_RIGHT);
        Nfac.setAlignment(Element.ALIGN_RIGHT);

        document.add(fecha1);
        document.add(futuros);
        document.add(rut);
        document.add(direccion);
        document.add(telefono);
        document.add(nombre_empresa);
        document.add(tipodoc);
        document.add(Nfac);
        document.add(cliente);
        document.add(dircliente);
        document.add(rutcli);

        PdfPTable tabla = new PdfPTable(4);
        tabla.setSpacingBefore(25);
        tabla.setSpacingAfter(25);

        //creo encabezado de tabla
        PdfPCell codigo = new PdfPCell(new Phrase("Proveedor".toUpperCase()));
        PdfPCell descripcion = new PdfPCell(new Phrase("descripcion".toUpperCase()));
        PdfPCell ecantidad = new PdfPCell(new Phrase("cantidad".toUpperCase()));
        PdfPCell eprecio = new PdfPCell(new Phrase("precio".toUpperCase()));

        tabla.setHeaderRows(1);
        tabla.setWidthPercentage(100f);

        //alineamos las frases del cabezal
        codigo.setHorizontalAlignment(Element.ALIGN_CENTER);
        descripcion.setHorizontalAlignment(Element.ALIGN_CENTER);
        ecantidad.setHorizontalAlignment(Element.ALIGN_CENTER);
        eprecio.setHorizontalAlignment(Element.ALIGN_CENTER);

        //agrego cabezal de tabla
        tabla.addCell(codigo);
        tabla.addCell(descripcion);
        tabla.addCell(ecantidad);
        tabla.addCell(eprecio);

        //obtengo datos de la reserva para imprimir las distintas rows

        while (iter.hasNext()) {
            dtItem = iter.next();
            Integer cantidad = dtItem.getCantidad();
            String oferta = dtItem.getOferta().getNombre();
            String precio;
            String proveedor;
            if (existeServicio(oferta)) {
                proveedor = getNkProveedorServicio(oferta);
                DtServicio dts = getDtServicio(oferta, proveedor);
                precio = String.valueOf(dts.getPrecio());
            } else {
                proveedor = getNkProveedorPromocion(oferta);
                DtPromocion dtp = getDTPromocion(oferta, proveedor);
                precio = dtp.getDescuento();
            }
            /*  String item = "<li>Nombre: <em>" + oferta + "</em>"
                + " - Cantidad: <em>" + cantidad + "</em>"
                + " - $:<em>" + precio + "</em>"
                + " - Proveedor: <em>" + proveedor + "</em></li>";*/
            //creo encabezado de tabla
            PdfPCell iproveedor = new PdfPCell(new Phrase(proveedor.toUpperCase()));

            PdfPCell icantidad = new PdfPCell(new Phrase(cantidad.toString()));
            PdfPCell iprecio = new PdfPCell(new Phrase(precio.toUpperCase()));

            tabla.setHeaderRows(1);

            //alineamos las frases del cabezal
            iproveedor.setHorizontalAlignment(Element.ALIGN_CENTER);
            icantidad.setHorizontalAlignment(Element.ALIGN_CENTER);
            iprecio.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(iproveedor);
            if (existeServicio(oferta)) {
                PdfPCell idescripcion = new PdfPCell(new Phrase("servicio: " + oferta));
                idescripcion.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(idescripcion);
            } else {
                PdfPCell idescripcion = new PdfPCell(new Phrase("Promo: " + oferta));
                idescripcion.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(idescripcion);
            }
            tabla.addCell(icantidad);
            tabla.addCell(iprecio);
        }

        /*      // las distintas rows de los articulos
              tabla.addCell(proveedor);
              tabla.addCell(oferta);
              tabla.addCell(cantidad);
              tabla.addCell(precio);
        */
        //el ulimo de la tabla que da el total

        PdfPCell celdaFinal = new PdfPCell(new Paragraph(""));
        PdfPCell celdaTotal = new PdfPCell(new Paragraph("total:"));
        PdfPCell celdaPrecioTotal = new PdfPCell(new Paragraph(rtotal));
        // Indicamos cuantas columnas ocupa la celda
        celdaFinal.setColspan(2);

        celdaTotal.setHorizontalAlignment(Element.ALIGN_RIGHT);
        celdaPrecioTotal.setHorizontalAlignment(Element.ALIGN_RIGHT);

        tabla.addCell(celdaFinal);
        tabla.addCell(celdaTotal);
        tabla.addCell(celdaPrecioTotal);
        document.add(tabla);
        document.close();
        if (request.getParameter("dispositivo").equals("true"))
            response.sendRedirect("Movil.Reservas.jsp");
        else
            response.sendRedirect("Usuario.jsp");
    } catch (DocumentException e) {
        e.printStackTrace();
    }
}