Example usage for com.lowagie.text.pdf PdfPTable setSpacingBefore

List of usage examples for com.lowagie.text.pdf PdfPTable setSpacingBefore

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfPTable setSpacingBefore.

Prototype

public void setSpacingBefore(float spacing) 

Source Link

Document

Sets the spacing before this table.

Usage

From source file:bucks.GenerateChecks.java

License:Open Source License

void generate_mb(Document document, int seq, String value, Image image, PdfWriter writer) {
    try {//from   ww  w .j  a v  a 2  s  .c om
        float[] widths = { 15f, 40f, 45f }; // percentages         
        PdfPTable table = new PdfPTable(widths);
        table.setWidthPercentage(100);
        table.setSpacingAfter(0f);
        table.setSpacingBefore(0f);
        table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        PdfPCell cell = new PdfPCell(image);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        // cell.setFixedHeight(46f);
        table.addCell(cell);
        Phrase phrase = new Phrase();
        Chunk ch = new Chunk("FARMERS' MARKET BUCKS\n", fntb2);
        phrase.add(ch);
        ch = new Chunk("Parks & Recreation\nBloomington, IN", fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        table.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("Issue Date___________ ", fnt10);
        phrase.add(ch);
        ch = new Chunk("No. " + seq, fnt10);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        table.addCell(cell);
        //
        // document.add(table);
        //
        phrase = new Phrase();
        ch = new Chunk("\nThis certificate is good for ", fnt);
        phrase.add(ch);
        ch = new Chunk("$" + value + ".00 ", fntb2);
        phrase.add(ch);
        ch = new Chunk("towards the purchase of ", fnt);
        phrase.add(ch);
        ch = new Chunk("eligible food items ", fntb);
        phrase.add(ch);
        ch = new Chunk("at the Bloomington Community Farmers' Market. ", fnt);
        phrase.add(ch);
        ch = new Chunk("No change allowed. \n", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        cell.setFixedHeight(48f);
        cell.setColspan(3);
        table.addCell(cell);

        document.add(table);
        //
        float[] widths2 = { 60f, 25f, 10f, 5f };
        table = new PdfPTable(widths2);
        table.setWidthPercentage(100);
        table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        //table.getDefaultCell().setPadding(0);
        table.setSpacingAfter(0f);
        table.setSpacingBefore(0f);
        //
        phrase = new Phrase();
        ch = new Chunk(
                "Customers shall redeem this certificate at Farmers' Market\nby December 1st of the year issued.",
                fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setVerticalAlignment(Element.ALIGN_BOTTOM);

        cell.setColspan(2);
        cell.setFixedHeight(81f);
        table.addCell(cell);
        //
        Barcode barcode = BarcodeFactory.createCode39("" + seq, false);
        // barcode text has problem, so we turned off
        // and decided to add it ourselves.
        barcode.setDrawingText(false);
        // barcode.setFont(new java.awt.Font("Arial", java.awt.Font.PLAIN, 16));
        // barcode.setLabel(""+seq);
        BufferedImage bi = BarcodeImageHandler.getImage(barcode);
        /*
        int width = bi.getWidth();
        int height = bi.getHeight();
        Graphics2D g2 = bi.createGraphics();
        g2.setColor(Color.BLACK);
        g2.drawString(""+seq, 60, 70);
        g2.dispose();
        */
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        //
        // added this hack to get rid of underline in the barcode
        // this worked on windows, but the text did not show up on linux
        // that is why we decided to abandon the text all the way
        // and add it ourselves
        /*
        BarcodeImageHandler.writePNG(barcode, baos);
        File bcImg = File.createTempFile("bc-", ".png");
        bcImg.deleteOnExit();
        byte[] imageBytes = baos.toByteArray();
        FileOutputStream fos = new FileOutputStream(bcImg);
        BarcodeImageHandler.writePNG(barcode, fos);
        */
        //
        // old
        ImageIO.write(bi, "png", baos);
        byte[] imageBytes = baos.toByteArray();
        //
        Image barCodeImage = Image.getInstance(imageBytes);

        barCodeImage.setRotationDegrees(90f);
        // barCodeImage.scalePercent(35f);
        barCodeImage.scalePercent(35f, 50f);
        // float widthf = barCodeImage.getWidth();
        // float heightf = barCodeImage.getHeight();

        cell = new PdfPCell(barCodeImage);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setPadding(0);
        cell.setLeading(0f, 0f);
        // cell.setFixedHeight(81f);
        table.addCell(cell);
        //
        // the barcode text that we added underneath the barcode
        //
        int textWidth = 53, textHeight = 50;
        BufferedImage bi2 = new BufferedImage(textWidth, textHeight, BufferedImage.TYPE_BYTE_BINARY);
        Graphics2D g = bi2.createGraphics();
        g.setFont(new java.awt.Font("Verdana", java.awt.Font.PLAIN, 10));
        g.setColor(Color.WHITE);
        g.fillRect(0, 0, textWidth, textHeight);
        g.setColor(Color.BLACK);
        g.drawString("" + seq, 5, 10);

        g.dispose();
        baos = new ByteArrayOutputStream();
        ImageIO.write(bi2, "png", baos);
        imageBytes = baos.toByteArray();
        Image barCodeTextImage = Image.getInstance(imageBytes);

        barCodeTextImage.setRotationDegrees(90f);
        cell = new PdfPCell(barCodeTextImage);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setPadding(0);
        cell.setLeading(0f, 0f);
        table.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("\nThis certificate is not refundable and cannot be replaced if lost or stolen.\n\n",
                fnts);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        cell.setFixedHeight(34f);
        table.addCell(cell);

        phrase = new Phrase();
        ch = new Chunk("\nMust have official stamp to be valid.\n\n", fnts);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        cell.setColspan(3);
        table.addCell(cell);
        document.add(table);
        //
        float[] widths4 = { 40f, 60f }; // percentages         
        table = new PdfPTable(widths4);
        table.setWidthPercentage(100);
        table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        table.setSpacingBefore(0f);
        table.setSpacingAfter(0f);
        phrase = new Phrase();
        ch = new Chunk("APPROVED BY THE STATE BOARD OF ACCOUNTS\nFOR THE CITY OF BLOOMINGTON, IN 2007\n\n\n",
                fnts);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);

        cell.setFixedHeight(40f); // 40
        table.addCell(cell);
        phrase = new Phrase();
        ch = new Chunk(
                "VENDERS SHALL REDEEM THIS CERTIFICATE THROUGH BLOOMINGTON'S\nPARKS & REC DEPT. BY DECEMBER 15TH OF THE YEAR ISSUED\n\n\n",
                fnts);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        table.addCell(cell);
        document.add(table);
    } catch (Exception ex) {
        System.err.println(ex);
    }

}

From source file:bucks.GenerateChecks.java

License:Open Source License

void generate_gc(Document document, int seq, String value, Image image, PdfWriter writer) {
    try {// w  w  w. jav  a2 s . c o  m
        float[] widths = { 13f, 54f, 33f }; // percents
        PdfPTable table = new PdfPTable(widths);
        table.setWidthPercentage(100);
        table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        table.setSpacingAfter(0f);
        table.setSpacingBefore(0f);
        PdfPCell cell = new PdfPCell(image);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        cell.setFixedHeight(46f);
        table.addCell(cell);
        Phrase phrase = new Phrase();
        Chunk ch = new Chunk("FARMERS' MARKET GIFT CERTIFICATE\n", fntb2);
        phrase.add(ch);
        ch = new Chunk("Parks & Recreation\nBloomington, IN", fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        table.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("Issue Date__________ ", fnt10);
        phrase.add(ch);
        ch = new Chunk("No. " + seq, fnt10);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        table.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("\nThis certificate is good for ", fnt);
        phrase.add(ch);
        ch = new Chunk("$" + value + ".00 ", fntb2);
        phrase.add(ch);
        ch = new Chunk("towards the purchase of ", fnt);
        phrase.add(ch);
        ch = new Chunk("products from ", fnt);
        phrase.add(ch);
        ch = new Chunk("the Bloomington Community Farmers' Market and A Fair of The Arts Vendors. ", fnt);
        phrase.add(ch);
        ch = new Chunk("Change may be given. \n", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        cell.setColspan(3);
        cell.setFixedHeight(48f);
        table.addCell(cell);
        document.add(table);
        //
        float[] widths2 = { 60f, 25f, 10f, 5f };
        table = new PdfPTable(widths2);
        table.setWidthPercentage(100);
        table.setSpacingBefore(0f);
        table.setSpacingAfter(0f);
        table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        //
        phrase = new Phrase();
        ch = new Chunk("Customers shall redeem this certificate at Market\nwithin one year of date issued. ",
                fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
        cell.setColspan(2);

        cell.setFixedHeight(81f);
        table.addCell(cell);

        Barcode barcode = BarcodeFactory.createCode39("" + seq, true);
        barcode.setDrawingText(false);
        BufferedImage bi = BarcodeImageHandler.getImage(barcode);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        //
        ImageIO.write(bi, "png", baos);
        byte[] imageBytes = baos.toByteArray();
        //
        Image barCodeImage = Image.getInstance(imageBytes);

        barCodeImage.setRotationDegrees(90);
        // barCodeImage.scalePercent(35f);
        barCodeImage.scalePercent(35f, 50f);
        cell = new PdfPCell(barCodeImage);
        //
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setPadding(0);
        cell.setLeading(0f, 0f);
        table.addCell(cell);
        //
        // adding text underneath the barcode
        //
        int textWidth = 53, textHeight = 50;
        BufferedImage bi2 = new BufferedImage(textWidth, textHeight, BufferedImage.TYPE_BYTE_BINARY);
        Graphics2D g = bi2.createGraphics();
        g.setFont(new java.awt.Font("Verdana", java.awt.Font.PLAIN, 10));
        g.setColor(Color.WHITE);
        g.fillRect(0, 0, textWidth, textHeight);
        g.setColor(Color.BLACK);
        g.drawString("" + seq, 5, 10);

        g.dispose();
        baos = new ByteArrayOutputStream();
        ImageIO.write(bi2, "png", baos);
        imageBytes = baos.toByteArray();
        Image barCodeTextImage = Image.getInstance(imageBytes);

        barCodeTextImage.setRotationDegrees(90f);
        cell = new PdfPCell(barCodeTextImage);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setPadding(0);
        cell.setLeading(0f, 0f);
        table.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("\nThis certificate is not refundable and cannot be replaced if lost or stolen.\n\n\n",
                fnts);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        cell.setFixedHeight(30f);
        table.addCell(cell);

        phrase = new Phrase();
        ch = new Chunk("\nMust have official stamp to be valid.\n\n", fnts);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        cell.setColspan(3);
        table.addCell(cell);
        document.add(table);
        //
        float[] widths3 = { 40f, 60f }; // percentages         
        table = new PdfPTable(widths3);
        table.setWidthPercentage(100);
        table.setSpacingBefore(0f);
        table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);

        phrase = new Phrase();
        ch = new Chunk("APPROVED BY THE STATE BOARD OF ACCOUNTS\nFOR THE CITY OF BLOOMINGTON, IN 2007\n\n\n",
                fnts);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        // cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
        cell.setFixedHeight(44f);
        table.addCell(cell);
        phrase = new Phrase();
        ch = new Chunk(
                "VENDERS SHALL REDEEM THIS CERTIFICATE THROUGH BLOOMINGTON'S\nPARKS & REC DEPT. BY DECEMBER 15TH OF THE YEAR RECEIVED\n\n\n",
                fnts);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        table.addCell(cell);

        document.add(table);
        // document.add( Chunk.NEWLINE );
    } catch (Exception ex) {
        System.err.println(ex);
    }
}

From source file:candelaria.presentacion.beans.DetalleFacturaControlador.java

public void imprimirFac() {
    //DateFormat dfDateFull = DateFormat.getDateInstance(DateFormat.FULL);
    try {//from w  w w  .  ja v  a2 s.c  o m

        //Generamos el archivo PDF
        String directorioArchivos;
        ServletContext ctx = (ServletContext) FacesContext.getCurrentInstance().getExternalContext()
                .getContext();
        directorioArchivos = ctx.getRealPath("/") + "reports";
        String name = directorioArchivos + "/document-factura.pdf";
        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(name));
        //PdfWriter writer = PdfWriter.getInstance(document,
        //new FileOutputStream("C:"));

        Paragraph paragraph = new Paragraph();
        Paragraph paragraph1 = new Paragraph();
        PdfPTable table = new PdfPTable(4);
        PdfPTable table1 = new PdfPTable(2);
        PdfPTable table2 = new PdfPTable(1);
        PdfPTable table3 = new PdfPTable(2);
        PdfPTable table5 = new PdfPTable(4);
        PdfPTable tablaF = new PdfPTable(1);
        PdfPTable tablaF1 = new PdfPTable(3);
        PdfPTable tablaF2 = new PdfPTable(3);

        paragraph.add("\n\n\n");
        paragraph.setAlignment(Paragraph.ALIGN_CENTER);

        paragraph.add("YUQUI OLGA");
        paragraph.setAlignment(Paragraph.ALIGN_CENTER);
        paragraph.add("\n");
        paragraph.add("Dir. La Candelaria Barrio Nuevo");
        paragraph.setAlignment(Paragraph.ALIGN_CENTER);
        paragraph.add("\n");
        paragraph.add("Telf: 3014019");
        paragraph.setAlignment(Paragraph.ALIGN_CENTER);
        paragraph.add("\n");
        paragraph.add("Penipe - Ecuador");
        paragraph.setAlignment(Paragraph.ALIGN_CENTER);
        paragraph.add("\n");
        paragraph.add("\n");
        paragraph.setAlignment(Paragraph.ALIGN_CENTER);
        paragraph.add("AUTORIZACION SRI __________ - RUC.: 0600750897001");
        paragraph.setAlignment(Paragraph.ALIGN_CENTER);
        paragraph.add("\n");
        paragraph.add("FACTURA: " + facturaSel.getId_factura());
        paragraph.setAlignment(Paragraph.ALIGN_CENTER);

        paragraph.add("\n\n\n");
        paragraph.setAlignment(Paragraph.ALIGN_CENTER);

        paragraph1.add("\n\n");
        paragraph.setAlignment(Paragraph.ALIGN_CENTER);

        document.open();

        //primera linea   
        PdfPCell cell5 = new PdfPCell(new Paragraph("Fecha: " + fecha_cambiada));
        //PdfPCell cell6 = new PdfPCell(new Paragraph("Factura #: " + facturaSel.getId_factura()));
        PdfPCell cell7 = new PdfPCell(new Paragraph("Cedula: " + facturaSel.getId_cliente().getRuc_cliente()));
        //segunda linea
        PdfPCell cell8 = new PdfPCell(
                new Paragraph("Nombre Cliente: " + facturaSel.getId_cliente().getNombres_cliente()
                        + facturaSel.getId_cliente().getApellidos_cliente()));
        //tercera fila
        PdfPCell cell9 = new PdfPCell(
                new Paragraph("Direccin: " + facturaSel.getId_cliente().getDireccion_cliente()));
        PdfPCell cell10 = new PdfPCell(
                new Paragraph("Tlefono: " + facturaSel.getId_cliente().getTelefono_cliente()));

        PdfPCell cellf1 = new PdfPCell(new Paragraph("SubTotal     " + totalHoja));
        PdfPCell cellf2 = new PdfPCell(new Paragraph("Impuesto Iva " + impuestoFactura));
        PdfPCell cellf21 = new PdfPCell(new Paragraph("___________________"));
        PdfPCell cellf22 = new PdfPCell(new Paragraph("___________________"));
        PdfPCell cellf3 = new PdfPCell(new Paragraph("TOTAL        " + totalFactura));
        PdfPCell cellf31 = new PdfPCell(new Paragraph("FIRMA AUTORIZADA"));
        PdfPCell cellf32 = new PdfPCell(new Paragraph("FIRMA CLIENTE"));
        PdfPCell cell11 = new PdfPCell(new Paragraph("Cantidad"));
        PdfPCell cell12 = new PdfPCell(new Paragraph("Descripcin"));
        PdfPCell cell13 = new PdfPCell(new Paragraph("V. Unitario"));
        PdfPCell cell14 = new PdfPCell(new Paragraph("V. Total"));

        cell5.setHorizontalAlignment(Element.ALIGN_LEFT);
        //cell6.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell7.setHorizontalAlignment(Element.ALIGN_RIGHT);

        cellf1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cellf2.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cellf3.setHorizontalAlignment(Element.ALIGN_RIGHT);

        cellf21.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellf31.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellf22.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellf32.setHorizontalAlignment(Element.ALIGN_CENTER);

        cell8.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell9.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell10.setHorizontalAlignment(Element.ALIGN_RIGHT);

        cellf21.setBorder(Rectangle.NO_BORDER);
        cellf31.setBorder(Rectangle.NO_BORDER);
        cellf22.setBorder(Rectangle.NO_BORDER);
        cellf32.setBorder(Rectangle.NO_BORDER);

        cell5.setBorder(Rectangle.NO_BORDER);
        //cell6.setBorder(Rectangle.NO_BORDER);
        cell7.setBorder(Rectangle.NO_BORDER);
        cell8.setBorder(Rectangle.NO_BORDER);

        cell9.setBorder(Rectangle.NO_BORDER);
        cell10.setBorder(Rectangle.NO_BORDER);
        //cell7.setBorder(Rectangle.NO_BORDER);
        //cell8.setBorder(Rectangle.NO_BORDER);

        cell11.setBorder(Rectangle.NO_BORDER);
        cell12.setBorder(Rectangle.NO_BORDER);
        cell13.setBorder(Rectangle.NO_BORDER);
        cell14.setBorder(Rectangle.NO_BORDER);

        cellf1.setBorder(Rectangle.NO_BORDER);
        cellf2.setBorder(Rectangle.NO_BORDER);
        cellf3.setBorder(Rectangle.NO_BORDER);

        cell11.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell12.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell13.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell14.setHorizontalAlignment(Element.ALIGN_RIGHT);

        table1.addCell(cell5);
        //table1.addCell(cell6);
        table1.addCell(cell7);
        //aadir segunda fila
        table2.addCell(cell8);
        //aadir tercera fila
        table3.addCell(cell9);
        table3.addCell(cell10);
        //aadir cuarta fila
        table5.addCell(cell11);
        table5.addCell(cell12);
        table5.addCell(cell13);
        table5.addCell(cell14);
        tablaF.addCell(cellf1);

        tablaF1.addCell(cellf21);
        tablaF1.addCell(cellf22);
        tablaF1.addCell(cellf2);
        tablaF2.addCell(cellf31);
        tablaF2.addCell(cellf32);
        tablaF2.addCell(cellf3);

        for (int x = 0; x < lstDetalleFactura.size(); x++) {

            PdfPCell cell1 = new PdfPCell(new Paragraph("" + lstDetalleFactura.get(x).getCantidad()));
            PdfPCell cell2 = new PdfPCell(new Paragraph(
                    "" + lstDetalleFactura.get(x).getId_producto().getId_categoria().getNombre_producto()));
            PdfPCell cell3 = new PdfPCell(new Paragraph(
                    "" + lstDetalleFactura.get(x).getId_producto().getId_categoria().getPrecio_producto()));
            PdfPCell cell4 = new PdfPCell(new Paragraph("" + lstDetalleFactura.get(x).getValor_total()));
            /* Chunk chunk = new Chunk(
             "\n" + lstDetalles.get(x).getCantidadDet() + "       " + lstDetalles.get(x).getIdSer().getNombreSer() + "             " + lstDetalles.get(x).getIdSer().getPrecioSer()
             + "                          " + lstDetalles.get(x).getPrecio());*/

            cell1.setBorder(Rectangle.NO_BORDER);
            cell2.setBorder(Rectangle.NO_BORDER);
            cell3.setBorder(Rectangle.NO_BORDER);
            cell4.setBorder(Rectangle.NO_BORDER);

            cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell2.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell3.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell4.setHorizontalAlignment(Element.ALIGN_RIGHT);

            cell1.setMinimumHeight(10f);
            cell2.setMinimumHeight(5f);

            table.setTotalWidth(100f);
            table.addCell(cell1);
            table.addCell(cell2);
            table.addCell(cell3);
            table.addCell(cell4);

            //aadir primera fila
            table.setSpacingBefore(30f);
            table.setSpacingAfter(50f);

            //paragraph4.add(chunk);
            //paragraph4.setAlignment(Paragraph.ALIGN_JUSTIFIED_ALL);
        }

        document.add(paragraph);
        document.add(table1);
        document.add(table2);
        document.add(table3);
        document.add(paragraph1);
        document.add(table5);
        document.add(table);
        document.add(tablaF);
        document.add(tablaF1);
        document.add(tablaF2);
        //document.setFooter(event);

        document.close();
        //----------------------------
        //Abrimos el archivo PDF
        FacesContext context = FacesContext.getCurrentInstance();
        HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
        response.setContentType("application/pdf");
        response.setHeader("Content-disposition", "inline=filename=" + name);
        try {
            response.getOutputStream().write(Util.getBytesFromFile(new File(name)));
            response.getOutputStream().flush();
            response.getOutputStream().close();
            context.responseComplete();

        } catch (IOException e) {
            e.printStackTrace();
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.concursive.connect.web.modules.wiki.utils.WikiPDFUtils.java

License:Open Source License

private static boolean parseContent(WikiPDFContext context, Wiki wiki, String content, Document document,
        PdfPCell cell, Connection db, ArrayList<Integer> wikiListTodo, ArrayList<Integer> wikiListDone,
        float cellWidth) throws Exception {

    LOG.debug("PARSING CONTENT: " + content);

    // Parse the wiki page
    int lastIndent = 0;
    boolean preTag = false;
    boolean pre = false;
    boolean code = false;
    boolean header = true;

    try {//from  w w  w .  j a v a 2 s  . co m

        BufferedReader in = new BufferedReader(new StringReader(content));
        String line = null;

        ArrayList unorderedParents = null;
        List thisList = null;
        Paragraph codeParagraph = null;

        while ((line = in.readLine()) != null) {
            // Tables
            if (line.startsWith("|")) {
                // @todo Close all ordered lists, unordered lists, and paragraphs

                // Parse the table
                line = parseTable(context, wiki, line, document, db, wikiListTodo, wikiListDone, in);

                if (line == null) {
                    continue;
                }
            }

            // Forms
            if (line.startsWith("[{form")) {
                // @todo close any lists or paragraphs

                // parseForm operates over all the lines that make up the form,
                // it will have to look forward so it returns an unparsed line
                parseForm(context, db, in, line, document, cell);
                continue;
            }

            // Handle code blocks
            // @todo chunk the content similar to WikiToHTMLUtils otherwise inaccurate
            if (line.startsWith("<pre>") || line.startsWith("<code>")) {
                if (!code && !pre) {
                    if (line.startsWith("<pre>")) {
                        preTag = true;
                        pre = true;
                    } else if (line.startsWith("<code>")) {
                        code = true;
                    }
                    codeParagraph = new Paragraph("", codeFont);
                    codeParagraph.setSpacingBefore(10);

                    if (pre && line.length() > ("<pre>").length()) {
                        int endOfLine = line.length();
                        if (line.endsWith("</pre>")) {
                            endOfLine = line.indexOf("</pre>");
                        }
                        // This line has some extra content that needs to be added
                        codeParagraph.add(new Chunk(
                                line.substring(line.indexOf("<pre>") + 5, endOfLine) + Chunk.NEWLINE));
                    }
                    if (code && line.length() > ("<code>").length()) {
                        int endOfLine = line.length();
                        if (line.endsWith("</code>")) {
                            endOfLine = line.indexOf("</code>");
                        }
                        // This line has some extra content that needs to be added
                        codeParagraph.add(new Chunk(
                                line.substring(line.indexOf("<code>") + 6, endOfLine) + Chunk.NEWLINE));
                    }
                    // See if this is a single line block
                    if (preTag && line.endsWith("</pre>")) {
                        // This is a single line block, so finish processing it
                    } else if (code && line.endsWith("</code>")) {
                        // This is a single line block, so finish processing it
                    } else {
                        // There are more lines to process, so do that
                        continue;
                    }
                }
            }
            if (line.startsWith("</code>") || line.endsWith("</code>")) {
                if (code) {
                    code = false;
                    if (line.indexOf("</code>") > 0 && !line.startsWith("<code>")) {
                        // This line has some extra content that needs to be added
                        codeParagraph
                                .add(new Chunk(line.substring(0, line.indexOf("</code>")) + Chunk.NEWLINE));
                    }
                    // Draw the final content
                    PdfPTable codeTable = new PdfPTable(1);
                    codeTable.setWidthPercentage(100);
                    codeTable.setSpacingBefore(10);
                    PdfPCell codeCell = new PdfPCell(codeParagraph);
                    codeCell.setPadding(20);
                    codeCell.setBorderColor(new Color(100, 100, 100));
                    codeCell.setBackgroundColor(new Color(200, 200, 200));
                    //            codeCell.setNoWrap(true);
                    codeTable.addCell(codeCell);
                    LOG.debug("document.add(codeTable)");
                    document.add(codeTable);
                    continue;
                }
            }
            if (line.startsWith("</pre>") || line.endsWith("</pre>")) {
                if (pre) {
                    preTag = false;
                    pre = false;
                    if (line.indexOf("</pre>") > 0 && !line.startsWith("<pre>")) {
                        // This line has some extra content that needs to be added
                        codeParagraph.add(new Chunk(line.substring(0, line.indexOf("</pre>")) + Chunk.NEWLINE));
                    }
                    // Draw the final content
                    PdfPTable codeTable = new PdfPTable(1);
                    codeTable.setWidthPercentage(100);
                    codeTable.setSpacingBefore(10);
                    PdfPCell codeCell = new PdfPCell(codeParagraph);
                    codeCell.setPadding(20);
                    codeCell.setBorderColor(new Color(100, 100, 100));
                    codeCell.setBackgroundColor(new Color(200, 200, 200));
                    //            codeCell.setNoWrap(true);
                    codeTable.addCell(codeCell);
                    LOG.debug("document.add(codeTable)");
                    document.add(codeTable);
                    continue;
                }
            }
            if (code || preTag) {
                // Append the chunk
                codeParagraph.add(new Chunk(line + Chunk.NEWLINE));
                continue;
            }

            // Section
            if (line.startsWith("=") && line.endsWith("=")) {
                // @todo close any open lists or paragraphs

                int hCount = parseHCount(line, "=");
                if (hCount > 6) {
                    hCount = 6;
                }
                String section = line.substring(line.indexOf("=") + hCount, line.lastIndexOf("=") - hCount + 1);
                header = true;
                context.foundHeader(hCount);
                String headerAnchor = null;

                // Store the h2's with anchors for table of contents or index
                if (hCount == 2) {
                    headerAnchor = StringUtils.toHtmlValue(section).replace(" ", "_");
                    context.getHeaderAnchors().put(headerAnchor, section);
                }
                if (hCount == 3) {
                    Paragraph title = new Paragraph(section.trim(), section2Font);
                    title.setSpacingBefore(10);
                    if (cell != null) {
                        LOG.debug("phrase.add(title)");
                        cell.addElement(title);
                    } else {
                        LOG.debug("document.add(title)");
                        document.add(title);
                    }
                } else if (hCount > 3) {
                    Paragraph title = new Paragraph(section.trim(), section3Font);
                    title.setSpacingBefore(10);
                    if (cell != null) {
                        LOG.debug("phrase.add(title)");
                        cell.addElement(title);
                    } else {
                        LOG.debug("document.add(title)");
                        document.add(title);
                    }
                } else {
                    Paragraph title = new Paragraph(section.trim(), sectionFont);
                    title.setSpacingBefore(10);
                    if (cell != null) {
                        LOG.debug("phrase.add(title)");
                        cell.addElement(title);
                    } else {
                        LOG.debug("document.add(title)");
                        document.add(title);
                    }
                }
                continue;
            }
            if (header) {
                header = false;
                if (line.trim().equals("")) {
                    // remove the extra space a user may leave after a header
                    continue;
                }
            }

            // Determine if this is a bulleted list
            if (line.startsWith("*") || line.startsWith("#")) {
                // Initialize the list array
                if (unorderedParents == null) {
                    unorderedParents = new ArrayList();
                    //            if (phrase != null) {
                    //              LOG.debug("phrase.add(new Paragraph(Chunk.NEWLINE))");
                    //              phrase.add(new Paragraph(Chunk.NEWLINE));
                    //            } else {
                    //              LOG.debug("document.add(new Paragraph(Chunk.NEWLINE))");
                    //              document.add(new Paragraph(Chunk.NEWLINE));
                    //            }
                }
                // Get the indent level
                boolean ol = line.startsWith("#");
                int hCount = WikiPDFUtils.parseHCount(line, ol ? "#" : "*");
                // Determine a shift in the tree
                if (lastIndent == 0) {
                    if (ol) {
                        thisList = new List(ol, 20);
                    } else {
                        thisList = new List(ol, 10);
                        thisList.setListSymbol(
                                new Chunk("\u2022", FontFactory.getFont(FontFactory.HELVETICA, 12)));
                    }
                    thisList.setIndentationLeft(36);
                    thisList.setIndentationRight(36);
                    unorderedParents.add(thisList);
                } else {
                    if (hCount > lastIndent) {
                        if (ol) {
                            thisList = new List(ol, 20);
                        } else {
                            thisList = new List(ol, 10);
                            thisList.setListSymbol(
                                    new Chunk("\u2022", FontFactory.getFont(FontFactory.HELVETICA, 12)));
                        }
                        thisList.setIndentationLeft(36);
                        thisList.setIndentationRight(36);
                        ((List) unorderedParents.get(unorderedParents.size() - 1)).add(thisList);
                        unorderedParents.add(thisList);
                    } else if (hCount < lastIndent) {
                        unorderedParents.remove(unorderedParents.size() - 1);
                        thisList = (List) unorderedParents.get(unorderedParents.size() - 1);
                    }
                }
                lastIndent = hCount;
                // Append the item...
                Paragraph thisItem = new Paragraph();
                parseLine(context, line.substring(hCount).trim(), thisItem, db, wikiListTodo, cellWidth, cell);
                thisList.add(new ListItem(thisItem));
                continue;
            }
            // List is finished, so append it to the document before working on
            // other paragraphs
            if (unorderedParents != null) {
                if (cell != null) {
                    LOG.debug("phrase.add((List) unorderedParents.get(0))");
                    cell.addElement((List) unorderedParents.get(0));
                } else {
                    LOG.debug("document.add((List) unorderedParents.get(0))");
                    document.add((List) unorderedParents.get(0));
                }
                unorderedParents = null;
                thisList = null;
                lastIndent = 0;
            }

            // Otherwise a simple paragraph
            Paragraph paragraph = new Paragraph();
            parseLine(context, line, paragraph, db, wikiListTodo, cellWidth, cell);
            if (cell != null) {
                LOG.debug("phrase.add(paragraph)");
                if (cell.getHorizontalAlignment() == Element.ALIGN_CENTER) {
                    paragraph.setAlignment(Element.ALIGN_CENTER);
                }
                paragraph.setSpacingBefore(5);
                cell.addElement(paragraph);
            } else {
                LOG.debug("document.add(paragraph)");
                paragraph.setSpacingBefore(5);
                document.add(paragraph);
            }
        }

        // Cleanup now that the lines are finished
        if (pre || code) {
            PdfPTable codeTable = new PdfPTable(1);
            codeTable.setWidthPercentage(100);
            codeTable.setSpacingBefore(10);
            PdfPCell codeCell = new PdfPCell(codeParagraph);
            codeCell.setPadding(20);
            codeCell.setBorderColor(new Color(100, 100, 100));
            codeCell.setBackgroundColor(new Color(200, 200, 200));
            //        codeCell.setNoWrap(true);
            codeTable.addCell(codeCell);
            LOG.debug("document.add(codeTable)");
            document.add(codeTable);
        }
        if (unorderedParents != null) {
            if (cell != null) {
                LOG.debug("phrase.add((List) unorderedParents.get(0))");
                cell.addElement((List) unorderedParents.get(0));
            } else {
                LOG.debug("document.add((List) unorderedParents.get(0))");
                document.add((List) unorderedParents.get(0));
            }
        }
        in.close();
    } catch (Exception e) {
        LOG.error("parseContent", e);
    }
    return true;
}

From source file:com.concursive.connect.web.modules.wiki.utils.WikiPDFUtils.java

License:Open Source License

private static String parseTable(WikiPDFContext context, Wiki wiki, String line, Document document,
        Connection db, ArrayList<Integer> wikiListTodo, ArrayList<Integer> wikiListDone, BufferedReader in)
        throws Exception {
    if (line == null) {
        return null;
    }//from   w w w  .  j av a2  s  .  co m
    PdfPTable pdfTable = null;
    int columnCount = 0;
    int rowCount = 0;

    // Keep track of the table's custom styles
    HashMap<Integer, String> cStyle = new HashMap<Integer, String>();

    while (line != null && (line.startsWith("|") || line.startsWith("!"))) {

        // Build a complete line
        String lineToParse = line;
        while (!line.endsWith("|")) {
            line = in.readLine();
            if (line == null) {
                // there is an error in the line to process
                return null;
            }
            if (line.startsWith("!")) {
                lineToParse += CRLF + line.substring(1);
            }
        }
        line = lineToParse;

        // Determine if the row can output
        boolean canOutput = true;

        ++rowCount;

        String cellType = null;
        Scanner sc = null;
        if (line.startsWith("||") && line.endsWith("||")) {
            cellType = "th";
            sc = new Scanner(line).useDelimiter("[|][|]");
            //        sc = new Scanner(line.substring(2, line.length() - 2)).useDelimiter("[|][|]");
        } else if (line.startsWith("|")) {
            cellType = "td";
            sc = new Scanner(line.substring(1, line.length() - 1)).useDelimiter("\\|(?=[^\\]]*(?:\\[|$))");
        }

        if (sc != null) {

            if (rowCount == 1) {
                // Count the columns, get the specified widths too...
                while (sc.hasNext()) {
                    ++columnCount;
                    sc.next();
                }
                // Reset the scanner now that the columns have been counted
                if (line.startsWith("||") && line.endsWith("||")) {
                    sc = new Scanner(line).useDelimiter("[|][|]");
                } else if (line.startsWith("|")) {
                    sc = new Scanner(line.substring(1, line.length() - 1))
                            .useDelimiter("\\|(?=[^\\]]*(?:\\[|$))");
                }

                // Start the table
                pdfTable = new PdfPTable(columnCount);
                //pdfTable.setWidthPercentage(100);
                pdfTable.setHorizontalAlignment(Element.ALIGN_LEFT);
                pdfTable.setSpacingBefore(10);
                pdfTable.setWidthPercentage(100);
                pdfTable.setKeepTogether(true);
            }

            // Determine the column span
            int colSpan = 1;
            // Determine the cell being output
            int cellCount = 0;

            while (sc.hasNext()) {
                String cellData = sc.next();
                if (cellData.length() == 0) {
                    ++colSpan;
                    continue;
                }

                // Track the cell count being output
                ++cellCount;

                if (rowCount == 1) {
                    // Parse and validate the style input
                    LOG.debug("Checking style value: " + cellData);
                    if (cellData.startsWith("{") && cellData.endsWith("}")) {
                        String[] style = cellData.substring(1, cellData.length() - 1).split(":");
                        String attribute = style[0].trim();
                        String value = style[1].trim();
                        // Determine the width of each column and store it
                        if ("width".equals(attribute)) {
                            // Validate the width style
                            if (StringUtils.hasAllowedOnly("0123456789%.", value)) {
                                cStyle.put(cellCount, attribute + ": " + value + ";");
                            }
                        } else {
                            LOG.debug("Unsupported style: " + cellData);
                        }
                        canOutput = false;
                    }
                }

                // Output the header
                if (canOutput) {

                    PdfPCell cell = new PdfPCell();
                    cell.setPadding(10);
                    cell.setBorderColor(new Color(100, 100, 100));
                    if ("th".equals(cellType)) {
                        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                        cell.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
                    }
                    if (colSpan > 1) {
                        cell.setColspan(colSpan);
                    }

                    // Output the data
                    if (" ".equals(cellData) || "".equals(cellData)) {
                        // Put a blank space in blank cells for output consistency
                        cell.addElement(new Chunk(" "));
                        LOG.debug("   OUTPUTTING A BLANK");
                    } else {
                        // Output the cell as a complete wiki
                        float cellWidth = (100.0f / columnCount);
                        parseContent(context, wiki, cellData, document, cell, db, wikiListTodo, wikiListDone,
                                cellWidth);
                        LOG.debug("   OUTPUTTING CONTENT");
                    }
                    pdfTable.addCell(cell);
                }
            }
        }
        // read another line to see if it's part of the table
        line = in.readLine();
    }
    if (pdfTable != null) {
        LOG.debug("document.add(pdfTable)");
        document.add(pdfTable);
        //          document.add(Chunk.NEWLINE);
    }
    return line;
}

From source file:com.concursive.connect.web.modules.wiki.utils.WikiPDFUtils.java

License:Open Source License

protected static String parseForm(WikiPDFContext context, Connection db, BufferedReader in, String line,
        Document document, PdfPCell cell) throws Exception {
    if (line == null) {
        return line;
    }//from   w w  w .j a  v a 2  s  .  c o m
    CustomForm form = WikiToHTMLUtils.retrieveForm(in, line);
    LOG.debug("parseForm");
    for (CustomFormGroup group : form) {
        LOG.debug(" group...");
        // Start the table

        PdfPTable pdfTable = new PdfPTable(2);
        pdfTable.setHorizontalAlignment(Element.ALIGN_LEFT);
        pdfTable.setSpacingBefore(10);
        //      pdfTable.setWidthPercentage(100);
        pdfTable.setKeepTogether(true);

        if (group.getDisplay() && StringUtils.hasText(group.getName())) {
            // output the 1st row with a colspan of 2
            if (StringUtils.hasText(group.getName())) {
                Paragraph groupParagraph = new Paragraph(group.getName());
                PdfPCell groupCell = new PdfPCell(groupParagraph);
                groupCell.setHorizontalAlignment(Element.ALIGN_CENTER);
                groupCell.setColspan(2);
                groupCell.setPadding(20);
                groupCell.setBorderColor(new Color(100, 100, 100));
                groupCell.setBackgroundColor(new Color(200, 200, 200));
                groupCell.setNoWrap(true);
                pdfTable.addCell(groupCell);
            }
        }
        for (CustomFormField field : group) {
            LOG.debug("  field...");
            if (field.hasValue()) {
                // output the row (2 columns: label, value)
                Paragraph fieldLabelParagraph = new Paragraph(field.getLabel());
                PdfPCell fieldLabelCell = new PdfPCell(fieldLabelParagraph);
                fieldLabelCell.setPadding(20);
                fieldLabelCell.setBorderColor(new Color(100, 100, 100));
                //          fieldLabelCell.setNoWrap(true);
                pdfTable.addCell(fieldLabelCell);

                Paragraph fieldValueParagraph = new Paragraph(getFieldValue(context, field));
                PdfPCell fieldValueCell = new PdfPCell(fieldValueParagraph);
                fieldValueCell.setPadding(20);
                fieldValueCell.setBorderColor(new Color(100, 100, 100));
                //          fieldValueCell.setNoWrap(true);
                pdfTable.addCell(fieldValueCell);
            }
        }
        LOG.debug("document.add(pdfTable)");
        document.add(pdfTable);

    }
    return null;
}

From source file:com.conecta.sat.utils.BuildAsignaSoftPDF.java

@Override
protected void buildPdfDocument(Map<String, Object> map, Document document, PdfWriter writer,
        HttpServletRequest hsr, HttpServletResponse hsr1) throws Exception {
    //        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    System.out.println("Into BuildImportTokensPDF");
    hsr1.setContentType("application/pdf");
    DateFormat name = new SimpleDateFormat("ddMMyyyyhhmmss");
    hsr1.setHeader("Content-disposition",
            "attachment; filename=AsignaToken" + name.format(new Date()) + ".pdf");
    AsignaSoftPDF list = (AsignaSoftPDF) map.get("list");
    String nombreUsuario = (String) map.get("nombreUsuario");

    PdfPTable table = new PdfPTable(5);
    table.setWidthPercentage(100);/*from www .  j  a v  a  2  s.c  o m*/
    table.setSpacingBefore(10);

    Font font = FontFactory.getFont(FontFactory.HELVETICA);
    try {
        font.setFamily(fontName);
    } catch (Exception e) {
        font.setFamily("Verdana");
    }

    try {
        ServletContext servletContext = hsr.getSession().getServletContext();
        String relativeWebPath = logoPath;
        String absoluteDiskPath = servletContext.getRealPath(relativeWebPath);
        Image logo = Image.getInstance(absoluteDiskPath);
        //            Image logo = Image.getInstance("logo.png");
        System.out.println("La imagen se cargo correctamente");
        logo.scaleToFit(widthLogo, heightLogo);
        document.add(logo);
    } catch (Exception e) {
        System.err.println("ERROR" + Excepciones.getStackTrace(e));
        document.add(new Paragraph("Sin imagen " + logoPath));
    }
    font.setSize(fontSize + 3);
    Paragraph titulo = new Paragraph("Asignacin de Token a cliente", font);
    titulo.setAlignment(Element.ALIGN_RIGHT);
    document.add(titulo);

    Chunk CONNECT = new Chunk(new LineSeparator(0.5f, 100, java.awt.Color.BLACK, Element.ALIGN_CENTER, 3.5f));
    document.add(CONNECT);

    DateFormat df = new SimpleDateFormat("dd/MM/yyyy hh:mm a");
    font.setSize(fontSize + 2);
    Paragraph fecha = new Paragraph("Asignacin Correcta", font);
    fecha.setAlignment(Element.ALIGN_CENTER);
    document.add(fecha);

    //        Paragraph pNombre = new Paragraph( nombreUsuario , font);
    //        pNombre.setAlignment(Element.ALIGN_RIGHT);
    //        document.add(pNombre);

    font.setSize(fontSize);
    font.setColor(java.awt.Color.white);

    // define table header cell
    PdfPCell cell = new PdfPCell();
    java.awt.Color color = java.awt.Color.LIGHT_GRAY;
    cell.setBackgroundColor(color);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);

    cell.setPadding(5);

    // write table header
    cell.setPhrase(new Phrase("Nombre empleado", font));
    table.addCell(cell);

    cell.setPhrase(new Phrase("Fecha y Hora", font));
    table.addCell(cell);

    cell.setPhrase(new Phrase("Cliente", font));
    table.addCell(cell);

    cell.setPhrase(new Phrase("Token", font));
    table.addCell(cell);

    cell.setPhrase(new Phrase("Tipo de Token", font));
    table.addCell(cell);

    //        cell.setPhrase(new Phrase("Centro Financiero", font));
    //        table.addCell(cell);
    //         
    //        cell.setPhrase(new Phrase("Tipo", font));
    //        table.addCell(cell);
    //        
    //        cell.setPhrase(new Phrase("Cliente nico", font));
    //        table.addCell(cell);
    //        
    //        cell.setPhrase(new Phrase("Fecha de ultima modificacin", font));
    //        table.addCell(cell);

    Font font2 = FontFactory.getFont(FontFactory.HELVETICA);
    try {
        font2.setFamily(fontName);
    } catch (Exception e) {
        font2.setFamily("Verdana");
    }
    font2.setSize(fontSize);
    font2.setColor(java.awt.Color.black);
    // write table row data
    //        for (ImportTokensPDF pdf : list) {
    //        ImportTokensPDF pdf;
    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase(list.getNombre(), font2));
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase(df.format(list.getFecha()), font2));
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase(list.getCliente(), font2));
    table.addCell(cell);

    if (list.getToken().length() >= 14) {
        list.setTipo("SOFTTOKEN");
    } else {
        list.setTipo("HARDTOKEN");
    }

    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase(list.getToken(), font2));
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase(list.getTipo(), font2));
    table.addCell(cell);

    //            cell = new PdfPCell();
    //            cell.setHorizontalAlignment( Element.ALIGN_CENTER );
    //            cell.addElement( new Phrase(pdf.getCentro(),font2) );
    //            table.addCell(cell);
    //            
    //            cell = new PdfPCell();
    //            cell.setHorizontalAlignment( Element.ALIGN_CENTER );
    //            cell.addElement( new Phrase(pdf.getTipo(),font2) );
    //            table.addCell(cell);
    //            
    //            cell = new PdfPCell();
    //            cell.setHorizontalAlignment( Element.ALIGN_CENTER );
    //            cell.addElement( new Phrase(pdf.getCliente(),font2) );
    //            table.addCell(cell);
    //            
    //            cell = new PdfPCell();
    //            cell.setHorizontalAlignment( Element.ALIGN_CENTER );
    //            cell.addElement( new Phrase(pdf.getLastUpdate(),font2) );
    //            table.addCell(cell);
    //        }

    document.add(table);
}

From source file:com.conecta.sat.utils.BuildAsignaTokenCenFinPDF.java

@Override
protected void buildPdfDocument(Map<String, Object> map, Document document, PdfWriter writer,
        HttpServletRequest hsr, HttpServletResponse hsr1) throws Exception {
    //        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    System.out.println("Into BuildImportTokensPDF");
    hsr1.setContentType("application/pdf");
    DateFormat name = new SimpleDateFormat("ddMMyyyyhhmmss");
    hsr1.setHeader("Content-disposition",
            "attachment; filename=AsignacionTokensCentroFinanciero" + name.format(new Date()) + ".pdf");
    AsignaTokenCenFinPDF list = (AsignaTokenCenFinPDF) map.get("list");
    String nombreUsuario = (String) map.get("nombreUsuario");

    PdfPTable table = new PdfPTable(2);
    table.setWidthPercentage(100);//from   w ww  . ja  v a  2 s .  c om
    table.setSpacingBefore(10);

    Font font = FontFactory.getFont(FontFactory.HELVETICA);
    try {
        font.setFamily(fontName);
    } catch (Exception e) {
        font.setFamily("Verdana");
    }

    try {
        ServletContext servletContext = hsr.getSession().getServletContext();
        String relativeWebPath = logoPath;
        String absoluteDiskPath = servletContext.getRealPath(relativeWebPath);
        Image logo = Image.getInstance(absoluteDiskPath);
        //            Image logo = Image.getInstance("logo.png");
        System.out.println("La imagen se cargo correctamente");
        logo.scaleToFit(widthLogo, heightLogo);
        document.add(logo);
    } catch (Exception e) {
        System.err.println("ERROR" + Excepciones.getStackTrace(e));
        document.add(new Paragraph("Sin imagen " + logoPath));
    }
    font.setSize(fontSize + 3);
    Paragraph titulo = new Paragraph("Asignacin de Hard Token", font);
    titulo.setAlignment(Element.ALIGN_RIGHT);
    document.add(titulo);

    Chunk CONNECT = new Chunk(new LineSeparator(0.5f, 100, java.awt.Color.BLACK, Element.ALIGN_CENTER, 3.5f));
    document.add(CONNECT);

    DateFormat df = new SimpleDateFormat("dd/MM/yyyy hh:mm a");
    font.setSize(fontSize + 2);
    Paragraph fecha = new Paragraph("Asignacin de Tokens a Centro Financiero", font);
    fecha.setAlignment(Element.ALIGN_CENTER);
    document.add(fecha);

    //        Paragraph pNombre = new Paragraph( nombreUsuario , font);
    //        pNombre.setAlignment(Element.ALIGN_RIGHT);
    //        document.add(pNombre);

    font.setSize(fontSize);
    font.setColor(java.awt.Color.white);

    // define table header cell
    PdfPCell cell = new PdfPCell();
    java.awt.Color color = java.awt.Color.LIGHT_GRAY;
    cell.setBackgroundColor(color);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);

    cell.setPadding(5);

    // write table header
    //        cell.setPhrase(new Phrase("Usuario que importo en token", font));
    //        table.addCell(cell);
    //         
    //        cell.setPhrase(new Phrase("Fecha y Hora", font));
    //        table.addCell(cell);
    //        
    //        cell.setPhrase(new Phrase("Tokens importados", font));
    //        table.addCell(cell);

    //        cell.setPhrase(new Phrase("Centro Financiero", font));
    //        table.addCell(cell);
    //         
    //        cell.setPhrase(new Phrase("Tipo", font));
    //        table.addCell(cell);
    //        
    //        cell.setPhrase(new Phrase("Cliente nico", font));
    //        table.addCell(cell);
    //        
    //        cell.setPhrase(new Phrase("Fecha de ultima modificacin", font));
    //        table.addCell(cell);

    Font font2 = FontFactory.getFont(FontFactory.HELVETICA);
    try {
        font2.setFamily(fontName);
    } catch (Exception e) {
        font2.setFamily("Verdana");
    }
    font2.setSize(fontSize);
    font2.setColor(java.awt.Color.black);
    // write table row data
    //        for (ImportTokensPDF pdf : list) {
    //        ImportTokensPDF pdf;
    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase("Nombre empleado", font2));
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase(list.getNombre(), font2));
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase("Fecha de Asignacin", font2));
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase(df.format(list.getFecha()), font2));
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase("Centro Financiero asignado", font2));
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase(list.getCentroFinanciero(), font2));
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase("Tokens asignados", font2));
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase(list.getTokens(), font2));
    table.addCell(cell);

    document.add(table);
}

From source file:com.conecta.sat.utils.BuildBitacoraPDF.java

@Override
protected void buildPdfDocument(Map<String, Object> map, Document document, PdfWriter writer,
        HttpServletRequest hsr, HttpServletResponse hsr1) throws Exception {
    //        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    hsr1.setContentType("application/pdf");
    DateFormat name = new SimpleDateFormat("ddMMyyyyhhmmss");
    hsr1.setHeader("Content-disposition", "attachment; filename=Bitacora" + name.format(new Date()) + ".pdf");
    List<BitacoraPDF> list = (List<BitacoraPDF>) map.get("listBitacora");
    String nombreUsuario = (String) map.get("nombreUsuario");

    PdfPTable table = new PdfPTable(columnas);
    table.setWidthPercentage(100);//from ww w. jav  a  2  s .c  o m
    table.setSpacingBefore(10);

    Font font = FontFactory.getFont(FontFactory.HELVETICA);
    try {
        font.setFamily(fontName);
    } catch (Exception e) {
        font.setFamily("Verdana");
    }

    try {
        ServletContext servletContext = hsr.getSession().getServletContext();
        String relativeWebPath = logoPath;
        String absoluteDiskPath = servletContext.getRealPath(relativeWebPath);
        Image logo = Image.getInstance(absoluteDiskPath);
        //            Image logo = Image.getInstance("logo.png");
        System.out.println("La imagen se cargo correctamente");
        logo.scaleToFit(widthLogo, heightLogo);
        document.add(logo);
    } catch (Exception e) {
        System.err.println("ERROR" + Excepciones.getStackTrace(e));
        document.add(new Paragraph("Sin imagen " + logoPath));
    }
    font.setSize(fontSize + 3);
    Paragraph titulo = new Paragraph("Bitcora de Actividades", font);
    titulo.setAlignment(Element.ALIGN_RIGHT);
    document.add(titulo);

    Chunk CONNECT = new Chunk(new LineSeparator(0.5f, 100, java.awt.Color.BLACK, Element.ALIGN_CENTER, 3.5f));
    document.add(CONNECT);

    DateFormat df = new SimpleDateFormat("dd/MM/yyyy hh:mm a");
    font.setSize(fontSize + 2);
    Paragraph fecha = new Paragraph(df.format(new Date()), font);
    fecha.setAlignment(Element.ALIGN_RIGHT);
    document.add(fecha);

    Paragraph pNombre = new Paragraph(nombreUsuario, font);
    pNombre.setAlignment(Element.ALIGN_RIGHT);
    document.add(pNombre);

    font.setSize(fontSize);
    font.setColor(java.awt.Color.white);

    // define table header cell
    PdfPCell cell = new PdfPCell();
    java.awt.Color color = java.awt.Color.LIGHT_GRAY;
    cell.setBackgroundColor(color);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);

    cell.setPadding(5);

    // write table header
    cell.setPhrase(new Phrase("Nombre de usuario", font));
    table.addCell(cell);

    cell.setPhrase(new Phrase("Bitcora", font));
    table.addCell(cell);

    cell.setPhrase(new Phrase("ltima fecha de Modificaciones", font));
    table.addCell(cell);

    Font font2 = FontFactory.getFont(FontFactory.HELVETICA);
    try {
        font2.setFamily(fontName);
    } catch (Exception e) {
        font2.setFamily("Verdana");
    }
    font2.setSize(fontSize);
    font2.setColor(java.awt.Color.black);
    // write table row data
    df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    for (BitacoraPDF bitacora : list) {
        cell = new PdfPCell();
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.addElement(new Phrase(bitacora.getNombre(), font2));
        table.addCell(cell);
        cell = new PdfPCell();
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.addElement(new Phrase(bitacora.getMensaje(), font2));
        table.addCell(cell);
        cell = new PdfPCell();
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.addElement(new Phrase(bitacora.getFecha(), font2));
        table.addCell(cell);
        cell = new PdfPCell();
    }

    document.add(table);
}

From source file:com.conecta.sat.utils.BuildDesactivarSoftPDF.java

@Override
protected void buildPdfDocument(Map<String, Object> map, Document document, PdfWriter writer,
        HttpServletRequest hsr, HttpServletResponse hsr1) throws Exception {
    //        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    System.out.println("Into BuildImportTokensPDF");
    hsr1.setContentType("application/pdf");
    DateFormat name = new SimpleDateFormat("ddMMyyyyhhmmss");
    hsr1.setHeader("Content-disposition",
            "attachment; filename=DesactivarToken" + name.format(new Date()) + ".pdf");
    AsignaSoftPDF list = (AsignaSoftPDF) map.get("list");
    String nombreUsuario = (String) map.get("nombreUsuario");

    PdfPTable table = new PdfPTable(5);
    table.setWidthPercentage(100);//from   w  ww.j  a va2 s.  com
    table.setSpacingBefore(10);

    Font font = FontFactory.getFont(FontFactory.HELVETICA);
    try {
        font.setFamily(fontName);
    } catch (Exception e) {
        font.setFamily("Verdana");
    }

    try {
        ServletContext servletContext = hsr.getSession().getServletContext();
        String relativeWebPath = logoPath;
        String absoluteDiskPath = servletContext.getRealPath(relativeWebPath);
        Image logo = Image.getInstance(absoluteDiskPath);
        //            Image logo = Image.getInstance("logo.png");
        System.out.println("La imagen se cargo correctamente");
        logo.scaleToFit(widthLogo, heightLogo);
        document.add(logo);
    } catch (Exception e) {
        System.err.println("ERROR" + Excepciones.getStackTrace(e));
        document.add(new Paragraph("Sin imagen " + logoPath));
    }
    font.setSize(fontSize + 3);
    Paragraph titulo = new Paragraph("Desactivacin de Token a cliente", font);
    titulo.setAlignment(Element.ALIGN_RIGHT);
    document.add(titulo);

    Chunk CONNECT = new Chunk(new LineSeparator(0.5f, 100, java.awt.Color.BLACK, Element.ALIGN_CENTER, 3.5f));
    document.add(CONNECT);

    DateFormat df = new SimpleDateFormat("dd/MM/yyyy hh:mm a");
    font.setSize(fontSize + 2);
    Paragraph fecha = new Paragraph("Cambio de Status Correcto", font);
    fecha.setAlignment(Element.ALIGN_CENTER);
    document.add(fecha);

    //        Paragraph pNombre = new Paragraph( nombreUsuario , font);
    //        pNombre.setAlignment(Element.ALIGN_RIGHT);
    //        document.add(pNombre);

    font.setSize(fontSize);
    font.setColor(java.awt.Color.white);

    // define table header cell
    PdfPCell cell = new PdfPCell();
    java.awt.Color color = java.awt.Color.LIGHT_GRAY;
    cell.setBackgroundColor(color);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);

    cell.setPadding(5);

    // write table header
    cell.setPhrase(new Phrase("Nombre empleado", font));
    table.addCell(cell);

    cell.setPhrase(new Phrase("Fecha y Hora", font));
    table.addCell(cell);

    cell.setPhrase(new Phrase("Cliente", font));
    table.addCell(cell);

    cell.setPhrase(new Phrase("Token", font));
    table.addCell(cell);

    cell.setPhrase(new Phrase("Tipo de Token", font));
    table.addCell(cell);

    //        cell.setPhrase(new Phrase("Centro Financiero", font));
    //        table.addCell(cell);
    //         
    //        cell.setPhrase(new Phrase("Tipo", font));
    //        table.addCell(cell);
    //        
    //        cell.setPhrase(new Phrase("Cliente nico", font));
    //        table.addCell(cell);
    //        
    //        cell.setPhrase(new Phrase("Fecha de ultima modificacin", font));
    //        table.addCell(cell);
    if (list.getToken().length() < 8) {
        list.setTipo("SoftToken");
    } else {
        list.setTipo("HardToken");
    }

    Font font2 = FontFactory.getFont(FontFactory.HELVETICA);
    try {
        font2.setFamily(fontName);
    } catch (Exception e) {
        font2.setFamily("Verdana");
    }
    font2.setSize(fontSize);
    font2.setColor(java.awt.Color.black);
    // write table row data
    //        for (ImportTokensPDF pdf : list) {
    //        ImportTokensPDF pdf;
    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase(list.getNombre(), font2));
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase(df.format(list.getFecha()), font2));
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase(list.getCliente(), font2));
    table.addCell(cell);
    if (list.getToken().length() > 8) {
        list.setTipo("SOFTTOKEN");
    } else {
        list.setTipo("HARDTOKEN");
    }
    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase(list.getToken(), font2));
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase(list.getTipo(), font2));
    table.addCell(cell);

    //            cell = new PdfPCell();
    //            cell.setHorizontalAlignment( Element.ALIGN_CENTER );
    //            cell.addElement( new Phrase(pdf.getCentro(),font2) );
    //            table.addCell(cell);
    //            
    //            cell = new PdfPCell();
    //            cell.setHorizontalAlignment( Element.ALIGN_CENTER );
    //            cell.addElement( new Phrase(pdf.getTipo(),font2) );
    //            table.addCell(cell);
    //            
    //            cell = new PdfPCell();
    //            cell.setHorizontalAlignment( Element.ALIGN_CENTER );
    //            cell.addElement( new Phrase(pdf.getCliente(),font2) );
    //            table.addCell(cell);
    //            
    //            cell = new PdfPCell();
    //            cell.setHorizontalAlignment( Element.ALIGN_CENTER );
    //            cell.addElement( new Phrase(pdf.getLastUpdate(),font2) );
    //            table.addCell(cell);
    //        }

    document.add(table);
}