Example usage for com.itextpdf.text Element ALIGN_MIDDLE

List of usage examples for com.itextpdf.text Element ALIGN_MIDDLE

Introduction

In this page you can find the example usage for com.itextpdf.text Element ALIGN_MIDDLE.

Prototype

int ALIGN_MIDDLE

To view the source code for com.itextpdf.text Element ALIGN_MIDDLE.

Click Source Link

Document

A possible value for vertical alignment.

Usage

From source file:modelo.plantillaPDF.java

public void pdf(int tiquet, int idOrden, String codOrden) {
    try {//from w ww.j  a  v a 2  s . c om

        String sql = "Select * from tiquet where idorden = '" + idOrden + "' and tiquet='" + tiquet + "'";
        rs = Consultar(sql);
        int id = 0;
        int numTiquet = 0;
        String ob = "";
        tiquet verTiquet = new tiquet();
        colores verColor = new colores();
        String colorUno = "";
        String colorDos = "";
        System.out.print("id de la orden en el tiquet:" + idOrden);
        ArrayList<String> lista = new ArrayList<String>();
        int c1 = 0, c2 = 0, c3 = 0, c4 = 0, c5 = 0, c6 = 0, c7 = 0, c8 = 0, c9 = 0, c10 = 0, c11 = 0, c12 = 0,
                c13 = 0, c14 = 0, c15 = 0;
        int c16 = 0, c17 = 0, c18 = 0, c19 = 0, c20 = 0, c21 = 0, c22 = 0, c23 = 0, c24 = 0, c25 = 0, c26 = 0,
                c27 = 0, c28 = 0, c29 = 0;
        int c30 = 0, c31 = 0, c32 = 0;
        //rs.last();
        int cuantos = rs.getRow();
        //System.out.print("puestos:" + cuantos+ "orden: " + codOrden + "tiquet: " + tiquet);

        //Fecha actual en formato completo:
        //Tue Sep 23 01:18:48 CEST 2014
        Date fechaActual = new Date();
        // System.out.println(fechaActual);
        // System.out.println("---------------------------------------------");

        //Formateando la fecha:
        DateFormat formatoHora = new SimpleDateFormat("HH-mm-ss");
        DateFormat formatoFecha = new SimpleDateFormat("yyyy-MM-dd");
        DateFormat Fecha = new SimpleDateFormat("dd/MM/yyyy");
        //  System.out.println("Fecha: "+formatoFecha.format(fechaActual)+" Son las: "+formatoHora.format(fechaActual));

        //Directorio destino para las descargas
        File folder = new File("c:\\seiya\\tiquets");

        //Crea el directorio de destino en caso de que no exista
        folder.mkdirs();
        String fe = Fecha.format(fechaActual);

        int numeroAleatorio = (int) (Math.random() * 2500 + 1);
        //Nombre del fichero <strong>PDF</strong> Resultante de la ejecucion
        String dir = "C:\\seiya\\tiquets\\Tiquet_" + tiquet + ".pdf";
        ;
        // El archivo pdf que vamos a generar
        FileOutputStream fileOutputStream = new FileOutputStream(dir);

        //Creacion del documento con un tamao y unos margenes predeterminados
        Document document = new Document(PageSize.LETTER, 10, 10, 10, 1);

        //A DocWriter class for PDF con Java.
        //When this PdfWriter is added to a certain PdfDocument,
        //the <strong>PDF</strong> representation of every Element added to this Document will be written to the outputstream.
        //PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        // Obtener la instancia del PdfWriter
        PdfWriter writer = PdfWriter.getInstance(document, fileOutputStream);
        //LEADING = separacion entre lineas del documento
        writer.setInitialLeading(16);
        Rectangle rct = new Rectangle(36, 54, 559, 788);
        //Definimos un nombre y un tamao para el PageBox los nombres posibles son: crop?, trim?, art? and bleed?.
        writer.setBoxSize("art", rct);
        //Opens the document.
        //You have to open the document before you can begin to add content to the body of the document.
        document.open();
        //**************************************************************
        //Ejemplos de TABLE

        //Aadir tabla 15 columnas
        PdfPTable table = new PdfPTable(15);
        //   PdfPTable tabla = new PdfPTable(15);
        PdfPCell celda;
        //Aadir CABECERA

        PdfPCell cell;
        Image image = Image.getInstance("logo/logo.png");
        //    String col = "jhon";
        cell = new PdfPCell(image);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(4);
        cell.setRowspan(7);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase("Calle 12 # 6-68 Nia Ceci"));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(6);
        cell.setRowspan(2);

        table.addCell(cell);

        while (rs.next()) {

            c1 = rs.getInt(1);
            c2 = rs.getInt(2);
            c3 = rs.getInt(3);
            c4 = rs.getInt(4);
            c5 = rs.getInt(5);
            c6 = rs.getInt(8);
            c7 = rs.getInt(9);
            c8 = rs.getInt(10);
            c9 = rs.getInt(11);
            c10 = rs.getInt(12);
            c11 = rs.getInt(13);
            c12 = rs.getInt(14);
            c13 = rs.getInt(15);
            c14 = rs.getInt(16);
            c15 = rs.getInt(17);
            c16 = rs.getInt(18);
            c17 = rs.getInt(19);
            c18 = rs.getInt(21);
            c19 = rs.getInt(22);
            c20 = rs.getInt(23);
            c21 = rs.getInt(24);
            c22 = rs.getInt(25);
            c23 = rs.getInt(26);
            c24 = rs.getInt(28);
            c25 = rs.getInt(29);
            c26 = rs.getInt(30);
            c27 = rs.getInt(31);
            c28 = rs.getInt(32);

            colorUno = verColor.consultarNombreColorUno(c4);
            colorDos = verColor.consultarNombreColorDos(c5);
            ob = verTiquet.ConsultaObservacion(tiquet);

            System.out.print("Color Uno: " + colorUno);

            //cell.setBackgroundColor(BaseColor.BLUE);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase("TIKET #:"));
            cell.setColspan(2);
            cell.setRowspan(2);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            //cell.setBackgroundColor(BaseColor.GRAY);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase("" + tiquet));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            //cell.setBackgroundColor(BaseColor.ORANGE);
            cell.setColspan(3);
            cell.setRowspan(2);
            table.addCell(cell);
            //Aadir dos filas de celdas sin formato

            cell = new PdfPCell(new Phrase("Tel: 5783364"));
            cell.setColspan(6);
            cell.setRowspan(2);
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            //cell.setBackgroundColor(BaseColor.CYAN);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase("REF:"));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            //cell.setBackgroundColor(BaseColor.ORANGE);
            cell.setColspan(2);
            cell.setRowspan(2);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase("" + c6));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            //cell.setBackgroundColor(BaseColor.ORANGE);
            cell.setColspan(3);
            cell.setRowspan(2);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase("calzadoseiya@gmail.com"));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setColspan(6);
            cell.setRowspan(2);//para eliminar espacio cabecera reemplazo el 2 por 3
            table.addCell(cell);
            cell = new PdfPCell(new Phrase("PARES:"));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            //cell.setBackgroundColor(BaseColor.ORANGE);
            cell.setColspan(2);
            cell.setRowspan(2);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase("" + c7));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            //cell.setBackgroundColor(BaseColor.ORANGE);
            cell.setColspan(3);
            cell.setRowspan(2);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase("FECHA"));//espacio intermedio cabecera
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setColspan(2);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(fe));//espacio intermedio cabecera
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setColspan(4);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase("ORDEN:"));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            //cell.setBackgroundColor(BaseColor.ORANGE);
            cell.setColspan(2);
            cell.setRowspan(1);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase("" + codOrden));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            //cell.setBackgroundColor(BaseColor.ORANGE);
            cell.setColspan(3);
            cell.setRowspan(1);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase("CORTADA"));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setColspan(4);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(""));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setColspan(11);
            cell.setRowspan(1);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase("GUARNICION"));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setColspan(4);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(""));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setColspan(11);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase("MONTADA"));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setColspan(4);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(""));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setColspan(11);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase("EMPLANTILLADA"));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setColspan(4);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(""));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setColspan(11);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase("COLOR 1:"));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setColspan(3);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(colorUno));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setColspan(4);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase("COLOR 2:"));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setColspan(3);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(colorDos));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setColspan(5);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase("OBSERVACION"));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setColspan(4);
            cell.setRowspan(2);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(ob));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setColspan(11);
            cell.setRowspan(2);
            table.addCell(cell);

            table.addCell("21");
            table.addCell("22");
            table.addCell("23");
            table.addCell("24");
            table.addCell("25");
            table.addCell("26");
            table.addCell("27");
            table.addCell("28");
            table.addCell("29");
            table.addCell("30");
            table.addCell("31");
            table.addCell("32");
            table.addCell("33");
            table.addCell("34");
            table.addCell("35");

            table.addCell(" " + c8);
            table.addCell(" " + c9);
            table.addCell(" " + c10);
            table.addCell(" " + c11);
            table.addCell(" " + c12);
            table.addCell(" " + c13);
            table.addCell(" " + c14);
            table.addCell(" " + c15);
            table.addCell(" " + c16);
            table.addCell(" " + c17);
            table.addCell(" " + c18);
            table.addCell(" " + c19);
            table.addCell(" " + c20);
            table.addCell(" " + c21);
            table.addCell(" " + c22);

            table.addCell("36");
            table.addCell("37");
            table.addCell("38");
            table.addCell("39");
            table.addCell("40");
            table.addCell("41");
            table.addCell("42");
            table.addCell("43");
            table.addCell("44");
            table.addCell(" ");
            table.addCell(" ");
            table.addCell(" ");
            table.addCell(" ");
            table.addCell(" ");
            table.addCell(" ");

            table.addCell(" " + c23);
            table.addCell(" " + c24);
            table.addCell(" " + c25);
            table.addCell(" " + c26);
            table.addCell(" " + c27);
            table.addCell(" " + c28);
            table.addCell(" " + c29);
            table.addCell(" " + c30);
            table.addCell(" " + c31);
            table.addCell(" ");
            table.addCell(" ");
            table.addCell(" ");
            table.addCell(" ");
            table.addCell(" ");
            table.addCell(" ");

            document.add(table);
            String cadena = "";
            for (int i = 1; i <= 4; i++) {
                //Chunk chunkSeparador =  new Chunk(SEPARADOR);
                // document.add(chunkSeparador);
                // document.add(Chunk.NEWLINE);

                PdfPTable tabla = new PdfPTable(15);
                if (i == 1)
                    cadena = "EMPLANTILLADA";
                if (i == 2)
                    cadena = "MONTADA";

                if (i == 3) {
                    cadena = "GUARNICION";

                }
                if (i == 4)
                    cadena = "CORTADA";

                cell = new PdfPCell(
                        new Phrase("------------------------------------------------------------------------"));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(15);
                cell.setRowspan(1);
                tabla.addCell(cell);

                cell = new PdfPCell(new Phrase("CALZADO SEIYA"));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(5);
                cell.setRowspan(1);
                tabla.addCell(cell);
                cell = new PdfPCell(new Phrase(cadena));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(4);
                cell.setRowspan(1);
                tabla.addCell(cell);
                cell = new PdfPCell(new Phrase("TIQUET #"));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(3);
                cell.setRowspan(1);
                tabla.addCell(cell);
                cell = new PdfPCell(new Phrase("" + tiquet));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(3);
                cell.setRowspan(1);
                tabla.addCell(cell);

                cell = new PdfPCell(new Phrase("PARES:"));
                cell.setHorizontalAlignment(Font.BOLD);
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(2);
                cell.setRowspan(1);
                tabla.addCell(cell);
                cell = new PdfPCell(new Phrase("" + c7));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(3);
                cell.setRowspan(1);
                tabla.addCell(cell);

                cell = new PdfPCell(new Phrase(""));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(4);
                cell.setRowspan(1);
                tabla.addCell(cell);
                cell = new PdfPCell(new Phrase("REF:"));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(3);
                cell.setRowspan(1);
                tabla.addCell(cell);
                cell = new PdfPCell(new Phrase("" + c6));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(3);
                cell.setRowspan(1);
                tabla.addCell(cell);

                cell = new PdfPCell(new Phrase("COLOR 1:"));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(3);
                tabla.addCell(cell);
                cell = new PdfPCell(new Phrase(colorUno));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(4);
                tabla.addCell(cell);

                cell = new PdfPCell(new Phrase("COLOR 2:"));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(3);
                tabla.addCell(cell);
                cell = new PdfPCell(new Phrase(colorDos));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(5);
                tabla.addCell(cell);

                tabla.addCell("21");
                tabla.addCell("22");
                tabla.addCell("23");
                tabla.addCell("24");
                tabla.addCell("25");
                tabla.addCell("26");
                tabla.addCell("27");
                tabla.addCell("28");
                tabla.addCell("29");
                tabla.addCell("30");
                tabla.addCell("31");
                tabla.addCell("32");
                tabla.addCell("33");
                tabla.addCell("34");
                tabla.addCell("35");

                tabla.addCell(" " + c8);
                tabla.addCell(" " + c9);
                tabla.addCell(" " + c10);
                tabla.addCell(" " + c11);
                tabla.addCell(" " + c12);
                tabla.addCell(" " + c13);
                tabla.addCell(" " + c14);
                tabla.addCell(" " + c15);
                tabla.addCell(" " + c16);
                tabla.addCell(" " + c17);
                tabla.addCell(" ");
                tabla.addCell(" " + c20);
                tabla.addCell(" " + c21);
                tabla.addCell(" " + c22);
                tabla.addCell(" " + c23);

                tabla.addCell("36");
                tabla.addCell("37");
                tabla.addCell("38");
                tabla.addCell("39");
                tabla.addCell("40");
                tabla.addCell("41");
                tabla.addCell("42");
                tabla.addCell("43");
                tabla.addCell("44");
                tabla.addCell(" ");
                tabla.addCell(" ");
                tabla.addCell(" ");
                tabla.addCell(" ");
                tabla.addCell(" ");
                tabla.addCell(" ");

                tabla.addCell(" " + c24);
                tabla.addCell(" " + c25);
                tabla.addCell(" " + c26);
                tabla.addCell(" " + c27);
                tabla.addCell(" " + c28);
                tabla.addCell(" " + c29);
                tabla.addCell(" " + c30);
                tabla.addCell(" " + c31);
                tabla.addCell(" " + c32);
                tabla.addCell(" ");
                tabla.addCell(" ");
                tabla.addCell(" ");
                tabla.addCell(" ");
                tabla.addCell(" ");
                tabla.addCell(" ");

                document.add(tabla);

            }

            //document.add(new Paragraph(new Date().toString()));
            //FIN Ejemplos de TABLE
            //**************************************************************

            //**************************************************************
            // Cierre del documento
            document.close();
        }

    } catch (Exception ex) {
        System.out.println(ex.getMessage());
    }
}

From source file:mvjce.PDF.java

public static PdfPTable createinternalsTable() {
    // a table with five columns
    PdfPTable table = new PdfPTable(5);
    float f[] = new float[] { 0.5f, 3f, 1f, 1f, 1.5f };
    try {/*from ww w .ja  v  a2  s  . c  om*/
        table.setWidths(f);
    } catch (Exception e) {
        System.out.println(e);
    }
    // the cell object
    PdfPCell cell;
    // we add a cell with colspan 3
    cell = new PdfPCell(new Phrase("SI.No", new Font(FontFamily.TIMES_ROMAN, 9, Font.BOLD)));
    cell.setRowspan(3);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);
    cell = new PdfPCell(new Phrase("SUBJECT TITLE", new Font(FontFamily.TIMES_ROMAN, 9, Font.BOLD)));
    cell.setRowspan(3);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);
    cell = new PdfPCell(new Phrase("SUB CODE", new Font(FontFamily.TIMES_ROMAN, 9, Font.BOLD)));
    cell.setRowspan(3);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);
    cell = new PdfPCell(
            new Phrase("Internal" + internal + " Test Marks", new Font(FontFamily.TIMES_ROMAN, 9, Font.BOLD)));
    cell.setRowspan(3);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);
    cell = new PdfPCell(new Phrase("Attendance\nAS ON DATE", new Font(FontFamily.TIMES_ROMAN, 9, Font.BOLD)));
    cell.setRowspan(3);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);

    for (int i = 1; i <= 8; i++) {
        table.addCell(new Phrase(Integer.toString(i), new Font(FontFamily.TIMES_ROMAN, 9)));
        table.addCell(new Phrase(sub[i - 1], new Font(FontFamily.TIMES_ROMAN, 9)));
        table.addCell(new Phrase(subcode[i - 1], new Font(FontFamily.TIMES_ROMAN, 9)));
        table.addCell(new Phrase(intr[i - 1], new Font(FontFamily.TIMES_ROMAN, 9)));
        table.addCell(new Phrase(att[i - 1], new Font(FontFamily.TIMES_ROMAN, 9)));
    }
    return table;
    //}catch(Exception e){System.out.println(e);}return null;
}

From source file:mvjce.PDF.java

public static PdfPTable createexternalTable() {
    PdfPTable table = new PdfPTable(10);
    PdfPCell cell;/*from w  w  w.  java2 s  . c  o  m*/
    for (int i = 1; i <= 10; i++) {
        cell = new PdfPCell(new Phrase("sub" + Integer.toString(i), new Font(FontFamily.TIMES_ROMAN, 9)));
        cell.setRowspan(2);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table.addCell(cell);
    }
    for (int i = 1; i <= 10; i++) {
        cell = new PdfPCell(new Phrase("value" + Integer.toString(i), new Font(FontFamily.TIMES_ROMAN, 9)));
        cell.setRowspan(2);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table.addCell(cell);
    }
    return table;
}

From source file:org.cherchgk.actions.tournament.result.show.GetPDFTournamentResultAction.java

License:Apache License

public InputStream getDocument() throws DocumentException, IOException {
    Font normalFont = getNormalFont();
    Font boldFont = getBoldFont();

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Document document = new Document();
    PdfWriter.getInstance(document, out);
    document.open();/* www. j  a  va2 s . co m*/

    Paragraph tournamentNameParagraph = new Paragraph(tournament.getTitle(), boldFont);
    tournamentNameParagraph.setAlignment(Element.ALIGN_CENTER);
    document.add(tournamentNameParagraph);

    Paragraph tournamentDateParagraph = new Paragraph(tournament.getDateAsString(), boldFont);
    tournamentDateParagraph.setAlignment(Element.ALIGN_CENTER);
    document.add(tournamentDateParagraph);

    if (teamCategory != null) {
        Paragraph teamCategoryParagraph = new Paragraph(teamCategory.getTitle(), boldFont);
        teamCategoryParagraph.setAlignment(Element.ALIGN_CENTER);
        document.add(teamCategoryParagraph);
    }

    int numColumns = 3 + tournamentResult.getRankingAlgorithms().size();
    PdfPTable resultTable = new PdfPTable(numColumns);
    int[] widths = new int[numColumns];
    widths[0] = 1;
    widths[1] = 3;
    for (int i = 2; i < numColumns; i++) {
        widths[i] = 1;
    }
    resultTable.setWidths(widths);
    resultTable.setSpacingBefore(10f);

    PdfPCell cell = new PdfPCell(new Phrase("", boldFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setColspan(2);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    resultTable.addCell(cell);

    for (RankingAlgorithm rankingAlgorithm : tournamentResult.getRankingAlgorithms()) {
        cell = new PdfPCell(new Phrase(rankingAlgorithm.getPointName(), boldFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
        resultTable.addCell(cell);
    }

    cell = new PdfPCell(new Phrase("?", boldFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    resultTable.addCell(cell);

    boolean showTeamCategoryInTable = (teamCategory == null) && !tournament.getTeamCategories().isEmpty();

    for (TournamentResult.TeamResult teamResult : tournamentResult.getTeamResultList()) {
        if (showTeamCategoryInTable) {
            if (teamResult.getTeam().getTeamCategory() != null) {
                cell = new PdfPCell(new Phrase(teamResult.getTeam().getTeamCategory().getTitle(), normalFont));
            } else {
                cell = new PdfPCell(new Phrase("", normalFont));
            }
            resultTable.addCell(cell);
        }
        cell = new PdfPCell(new Phrase(teamResult.getTeam().getName(), normalFont));
        if (!showTeamCategoryInTable) {
            cell.setColspan(2);
        }
        resultTable.addCell(cell);
        for (Map<Team, RankingPoint> m : tournamentResult.getRankingPointsList()) {
            cell = new PdfPCell(new Phrase(m.get(teamResult.getTeam()).toString(), normalFont));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            resultTable.addCell(cell);
        }
        cell = new PdfPCell(new Phrase(teamResult.getPlace(), normalFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        resultTable.addCell(cell);
    }

    document.add(resultTable);
    document.close();

    return new ByteArrayInputStream(out.toByteArray());
}

From source file:org.fossa.rolp.util.PdfFormatHelper.java

License:Open Source License

public static PdfPTable buildFooterDienstsiegelLine(Font footerFont) throws DocumentException {
    PdfPCell leftCell = new PdfPCell(new Phrase("", footerFont));
    leftCell.setBorder(Rectangle.NO_BORDER);
    leftCell.setBorderWidth(1f);/*from   ww w. jav  a2  s  . c  om*/

    PdfPCell centerCell = new PdfPCell(new Phrase("Dienstsiegel der Schule", footerFont));
    centerCell.setBorder(Rectangle.NO_BORDER);
    centerCell.setBorderWidth(1f);
    centerCell.setHorizontalAlignment(Element.ALIGN_CENTER);

    PdfPCell rightCell = new PdfPCell(new Phrase("", footerFont));
    rightCell.setBorder(Rectangle.NO_BORDER);
    rightCell.setBorderWidth(1f);

    PdfPTable table = new PdfPTable(3);
    table.setHorizontalAlignment(Element.ALIGN_MIDDLE);
    table.setWidthPercentage(100f);
    table.addCell(leftCell);
    table.addCell(centerCell);
    table.addCell(rightCell);
    table.setWidths(new float[] { 0.3f, 0.3f, 0.3f });
    return table;
}

From source file:org.openlmis.web.view.pdf.requisition.RequisitionCellFactory.java

License:Open Source License

public static PdfPCell imageCell() throws BadElementException, IOException {
    Resource resource = new ClassPathResource(OK_IMAGE);
    Image image = Image.getInstance(resource.getFile().getAbsolutePath());
    PdfPCell cell = new PdfPCell(image);
    cell.setPadding(CELL_PADDING);/* w  w w  . j av a2s  . com*/
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    return cell;
}

From source file:org.qnot.passtab.PDFOutput.java

License:Open Source License

private void addCell(PdfPTable table, String str, boolean bold, boolean fill, boolean rightBorder,
        boolean bottomBorder) {
    Phrase phrase = withColor ? new Phrase(str, bold ? fontBold : font) : new Phrase(str, font);

    PdfPCell cell = new PdfPCell(phrase);

    cell.setBorder(Rectangle.NO_BORDER);
    cell.setPadding(0f);//  w  w  w .ja  va  2  s .  c o  m
    cell.setPaddingTop(2f);

    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);

    if (rightBorder) {
        cell.setBorderWidthRight(1f);
        cell.setPaddingRight(3f);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
    }
    if (bottomBorder) {
        cell.setBorderWidthBottom(1f);
        cell.setPaddingBottom(3f);
    }

    if (fill && this.withColor) {
        cell.setGrayFill(0.80f);
    }

    table.addCell(cell);
}

From source file:org.tvd.thptty.management.report.Report.java

private PdfPTable createStatisticsStudentPointTable() throws BadElementException {
    PdfPTable table = new PdfPTable(15);

    table.setWidthPercentage(100);/*from  w ww  . jav a 2s. c o m*/

    for (int i = 0; i < 3; i++) {
        Phrase phrase = new Phrase(cellTitles[i], tahomaBoldFont);
        PdfPCell cx = new PdfPCell(phrase);
        cx.setHorizontalAlignment(Element.ALIGN_CENTER);
        cx.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cx.setRowspan(3);
        table.addCell(cx);
    }

    for (int i = 3; i < 5; i++) {

        Phrase phrase = new Phrase(cellTitles[i], tahomaBoldFont);
        PdfPCell cx = new PdfPCell(phrase);
        cx.setHorizontalAlignment(Element.ALIGN_CENTER);
        cx.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cx.setColspan(6);
        table.addCell(cx);

    }

    for (int i = 5; i < 11; i++) {
        Phrase phrase = new Phrase(cellTitles[i], tahomaBoldFont);
        PdfPCell cx = new PdfPCell(phrase);
        cx.setHorizontalAlignment(Element.ALIGN_CENTER);
        cx.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cx.setColspan(2);
        table.addCell(cx);
    }

    for (int i = 11; i < 23; i++) {
        Phrase phrase = new Phrase(cellTitles[i], tahomaBoldFont);
        PdfPCell cx = new PdfPCell(phrase);
        cx.setHorizontalAlignment(Element.ALIGN_CENTER);
        cx.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table.addCell(cx);
    }
    table.setHeaderRows(3);

    Phrase phrase = null;
    for (int i = 0; rows != null && i < rows.size(); i++) {
        for (int k = 0; k < rows.get(i).getListCells().size(); k++) {
            phrase = new Phrase(rows.get(i).getListCells().get(k).getCellName(), tahomaSmallFont);
            PdfPCell cx = new PdfPCell(phrase);
            cx.setHorizontalAlignment(Element.ALIGN_CENTER);
            cx.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cx);
        }
    }
    float totalWidth = PageSize.A4.getWidth();

    float columnWidths[] = new float[15];
    for (int i = 0; i < columnWidths.length; i++) {
        columnWidths[i] = (float) (1.0 / 15) * totalWidth;
    }

    try {
        table.setWidthPercentage(columnWidths, PageSize.A4);
    } catch (DocumentException e) {
        e.printStackTrace();
    }
    return table;

}

From source file:org.unesco.jisis.printsort.BarCodeGenerator.java

public void generateBarCode() {
    /** Step 1: Create a Document*/
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);

    try {/*from  ww  w  .ja  va 2s  .c o m*/

        /** Step 2: Create PDF Writer*/
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("sanjaalDotCom_BarCode1.pdf"));

        /** Step 3: Open the document so that we can write over it.*/
        document.open();

        /** Step 4: We have to create a set of contents.*/
        contentByte = writer.getDirectContent();

        PdfPTable table = new PdfPTable(2);
        table.setWidthPercentage(100);
        table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
        table.getDefaultCell().setFixedHeight(70);

        String myText = "www.sanjaal.com"; // Text to encode

        table.addCell("CODE 39");
        table.addCell(new Phrase(new Chunk(createBarCode39(myText.toUpperCase()), 0, 0)));

        table.addCell("CODE 39 EXTENDED");
        table.addCell(new Phrase(new Chunk(createBarcode39Extended(myText), 0, 0)));

        table.addCell("CODE 128");
        table.addCell(new Phrase(new Chunk(createBarcode128(myText), 0, 0)));

        table.addCell("CODE INTERLEAVED");
        String myTextNum = "12345";
        table.addCell(new Phrase(new Chunk(createBarcodeInter25(myTextNum), 0, 0)));

        table.addCell("CODE POSTNET");
        table.addCell(new Phrase(new Chunk(createBarcodePostnet(myTextNum), 0, 0)));

        table.addCell("CODE PLANET");
        table.addCell(new Phrase(new Chunk(createBarcodePostnetPlanet(myTextNum), 0, 0)));

        String myTextEAN13 = "1234567890123";
        table.addCell("CODE EAN");
        table.addCell(new Phrase(new Chunk(createBarcodeEAN(myTextEAN13), 0, 0)));

        table.addCell("CODE EAN\nWITH\nSUPPLEMENTAL 5");
        table.addCell(new Phrase(new Chunk(createBARCodeEANSUPP(myTextEAN13, "12345"), 0, 0)));

        document.add(table);
    } catch (Exception de) {
        de.printStackTrace();
    }

    // step 5: we close the document
    document.close();
}

From source file:PDF.GenerateReportActivities.java

private PdfPTable TablaDatos() throws Exception {
    PdfPTable Datos_prof = new PdfPTable(5);
    Datos_prof.setWidths(new int[] { 2, 3, 2, 2, 2 });
    PdfPCell Titulo_tabla = new PdfPCell(new Phrase("Datos generales del Profesor", encabezadost));
    PdfPCell Nombre = new PdfPCell(new Phrase("Nombre del Profesor"));
    PdfPCell Matricula = new PdfPCell(new Phrase("No. de Empleado"));
    PdfPCell UA = new PdfPCell(new Phrase("Unidad Acadmica"));
    PdfPCell Puntos = new PdfPCell(new Phrase("Puntos obtenidos"));
    PdfPCell Nivel = new PdfPCell(new Phrase("Nivel de Beca"));

    Titulo_tabla.setHorizontalAlignment(Element.ALIGN_CENTER);
    Titulo_tabla.setVerticalAlignment(Element.ALIGN_MIDDLE);
    Titulo_tabla.setBackgroundColor(new BaseColor(153, 0, 76));
    Titulo_tabla.setColspan(5);//  w  w  w  . j a  v a  2s. c  o m
    Titulo_tabla.setExtraParagraphSpace(15f);
    Datos_prof.addCell(Titulo_tabla);

    Nombre.setHorizontalAlignment(Element.ALIGN_CENTER);
    Datos_prof.addCell(Nombre);

    Matricula.setHorizontalAlignment(Element.ALIGN_CENTER);
    Datos_prof.addCell(Matricula);

    UA.setHorizontalAlignment(Element.ALIGN_CENTER);
    Datos_prof.addCell(UA);

    Puntos.setHorizontalAlignment(Element.ALIGN_CENTER);
    Datos_prof.addCell(Puntos);

    Nivel.setHorizontalAlignment(Element.ALIGN_CENTER);
    Datos_prof.addCell(Nivel);

    /*Aqui van las consultas de los datos del profesor*/
    ResultSet rn, rt;
    String nom_usuario = null, id_usuario = null, u_a = null, puntaje_final = null, nivel = null;
    //Datos_prof.addCell("Hola");
    ResultSet rp = lb.executeQuery("SELECT * FROM usuario WHERE id_usuario = " + username);
    while (rp.next()) {
        nom_usuario = rp.getString("nom_usuario");
        id_usuario = rp.getString("id_usuario");
        u_a = rp.getString("u_a");
    }
    System.out.println(getUsername());
    rn = lb.executeQuery(
            "SELECT * FROM evaluador_evalua_profesor WHERE id_usuario_prof = '" + getUsername() + "'");
    while (rn.next()) {
        puntaje_final = rn.getString("puntaje_final");
        //Datos_prof.addCell(rn.getString("puntaje_final"));
    }
    rt = lb.executeQuery("SELECT * FROM profesor WHERE id_usuario = '" + getUsername() + "'");
    while (rt.next()) {
        nivel = rt.getString("nivel");
    }
    Datos_prof.addCell(nom_usuario);
    Datos_prof.addCell(id_usuario);
    Datos_prof.addCell(u_a);
    Datos_prof.addCell(puntaje_final);
    Datos_prof.addCell(nivel);
    return Datos_prof;
}