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:bouttime.report.award.AwardReport.java

License:Open Source License

/**
 * Generate an award report./*from  w  w  w. ja v a  2s  .  c o  m*/
 * @param dao Dao object to use to retrieve data.
 * @param session Session to generate the report for.
 * @param group Group to generate report for.  This takes precedence, so
 * if not null, then the report will be generated for this group.
 * @return True if the report was generated.
 */
private static boolean doReport(Dao dao, String session, Group group) {
    if (!dao.isOpen()) {
        return false;
    }

    // step 1: creation of a document-object
    Document document = new Document();

    try {

        // step 2: creation of the writer
        FileOutputStream fos = createOutputFile();
        if (fos == null) {
            return false;
        }
        PdfWriter.getInstance(document, fos);

        // step 3: we open the document
        document.open();

        // step 4: create and add content

        // create and add the header
        Paragraph p1 = new Paragraph(new Paragraph(
                String.format("%s    %s %s, %s", dao.getName(), dao.getMonth(), dao.getDay(), dao.getYear()),
                FontFactory.getFont(FontFactory.HELVETICA, 10)));
        document.add(p1);

        Paragraph p2 = new Paragraph(
                new Paragraph("Award Report", FontFactory.getFont(FontFactory.HELVETICA, 14)));
        p2.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(p2);

        Font headerFont = new Font(Font.FontFamily.TIMES_ROMAN, 12);
        Font detailFont = new Font(Font.FontFamily.TIMES_ROMAN, 10);
        PdfPCell headerCell = new PdfPCell();
        headerCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        headerCell.setPadding(3);
        headerCell.setBorderWidth(2);

        List<Group> groups;
        if (group != null) {
            groups = new ArrayList<Group>();
            groups.add(group);
        } else if (session != null) {
            groups = dao.getGroupsBySession(session);
        } else {
            groups = dao.getAllGroups();
        }

        for (Group g : groups) {

            // create and add the table
            PdfPTable datatable = new PdfPTable(4);
            int colWidths[] = { 30, 30, 30, 10 }; // percentage
            datatable.setWidths(colWidths);
            datatable.setWidthPercentage(100);
            datatable.getDefaultCell().setPadding(3);
            datatable.getDefaultCell().setBorderWidth(2);
            datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

            // The header has the group name
            headerCell.setPhrase(new Phrase(g.toString(), headerFont));
            headerCell.setColspan(4);
            datatable.addCell(headerCell);

            datatable.setHeaderRows(1); // this is the end of the table header

            datatable.getDefaultCell().setBorderWidth(1);
            datatable.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);

            List<Wrestler> wList = getSortedAwardList(g);

            int i = 0;
            for (Wrestler w : wList) {
                if ((i++ % 2) == 0) {
                    datatable.getDefaultCell().setGrayFill(0.9f);
                } else {
                    datatable.getDefaultCell().setGrayFill(1);
                }

                datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
                datatable.addCell(new Phrase(w.getFirstName(), detailFont));
                datatable.addCell(new Phrase(w.getLastName(), detailFont));
                datatable.addCell(new Phrase(w.getTeamName(), detailFont));
                datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
                Integer place = w.getPlace();
                String placeStr = (place == null) ? "" : place.toString();
                datatable.addCell(new Phrase(placeStr, detailFont));
            }

            datatable.setSpacingBefore(5f);
            datatable.setSpacingAfter(15f);
            document.add(datatable);
        }

    } catch (DocumentException de) {
        logger.error("Document Exception", de);
        return false;
    }

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

    return true;
}

From source file:bouttime.report.boutsequence.BoutSequenceReport.java

License:Open Source License

private static PdfPTable addBoutSequences(List<Wrestler> wList, String session) throws DocumentException {
    // create and add the table
    Font headerFont = new Font(Font.FontFamily.TIMES_ROMAN, 12);
    Font detailFont = new Font(Font.FontFamily.TIMES_ROMAN, 10);
    PdfPCell headerCell = new PdfPCell();
    headerCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    headerCell.setPadding(3);//from   www . ja  va2s .  c o m
    headerCell.setBorderWidth(2);
    PdfPTable datatable = new PdfPTable(3);
    int colWidths[] = { 5, 25, 70 }; // percentage
    datatable.setWidths(colWidths);
    datatable.setWidthPercentage(100);
    datatable.getDefaultCell().setPadding(3);
    datatable.getDefaultCell().setBorderWidth(2);
    datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

    headerCell.setPhrase(new Phrase("Mat", headerFont));
    datatable.addCell(headerCell);

    headerCell.setPhrase(new Phrase("Name", headerFont));
    datatable.addCell(headerCell);

    headerCell.setPhrase(new Phrase("Bout Sequence", headerFont));
    datatable.addCell(headerCell);

    datatable.setHeaderRows(1); // this is the end of the table header

    datatable.getDefaultCell().setBorderWidth(1);
    datatable.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);

    Collections.sort(wList, new WrestlerMatNameSort());

    int i = 0;
    for (Wrestler w : wList) {
        if (w.getGroup() == null) {
            logger.debug(String.format("Wrestler [%s] is not in a group, skipping.", w.getShortName()));
            continue;
        }

        if ((session != null) && !session.equalsIgnoreCase(w.getGroup().getSession())) {
            logger.debug(String.format("Wrestler [%s] is in a group but not in session %s, skipping.",
                    w.getShortName(), session));
            continue;
        }

        if ((i++ % 2) == 0) {
            datatable.getDefaultCell().setGrayFill(0.9f);
        } else {
            datatable.getDefaultCell().setGrayFill(1);
        }

        List<Bout> bList = BoutSequence.calculate(w);
        datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        datatable.addCell(new Phrase(w.getGroup().getMat(), detailFont));
        datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        datatable.addCell(new Phrase(String.format("%s %s", w.getFirstName(), w.getLastName()), detailFont));
        datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        String boutSequenceString = getBoutSequenceString(bList);
        datatable.addCell(new Phrase(boutSequenceString, detailFont));
    }

    datatable.setSpacingBefore(5f);
    datatable.setSpacingAfter(15f);
    return (i > 0 ? datatable : null);
}

From source file:bouttime.report.team.TeamReport.java

License:Open Source License

/**
 * Generate a detail report of the teams in the tournament.
 * This report includes the teams and all of the wrestlers on the team.
 * @param dao Dao object to use to retrieve data.
 * @return True if the report was generated.
 *//*from   w w w  .  jav  a2s.  co  m*/
public static boolean doDetail(Dao dao) {
    if (!dao.isOpen()) {
        return false;
    }

    // step 1: creation of a document-object
    Document document = new Document();

    try {

        // step 2: creation of the writer
        FileOutputStream fos = createOutputFile();
        if (fos == null) {
            return false;
        }
        PdfWriter.getInstance(document, fos);

        // step 3: we open the document
        document.open();

        // step 4: create and add content

        // create and add the header
        Paragraph p1 = new Paragraph(new Paragraph(
                String.format("%s    %s %s, %s", dao.getName(), dao.getMonth(), dao.getDay(), dao.getYear()),
                FontFactory.getFont(FontFactory.HELVETICA, 10)));
        document.add(p1);

        Paragraph p2 = new Paragraph(
                new Paragraph("Team Detail Report", FontFactory.getFont(FontFactory.HELVETICA, 14)));
        p2.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(p2);

        Font headerFont = new Font(Font.FontFamily.TIMES_ROMAN, 12);
        Font detailFont = new Font(Font.FontFamily.TIMES_ROMAN, 10);
        PdfPCell headerCell = new PdfPCell();
        headerCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        headerCell.setPadding(3);
        headerCell.setBorderWidth(2);

        List<String> teams = dao.getTeams();

        for (String t : teams) {

            List<Wrestler> wrestlers = dao.getWrestlersByTeam(t);
            int count = wrestlers.size();

            // create and add the table
            PdfPTable datatable = new PdfPTable(5);
            int colWidths[] = { 30, 30, 20, 10, 10 }; // percentage
            datatable.setWidths(colWidths);
            datatable.setWidthPercentage(100);
            datatable.getDefaultCell().setPadding(3);
            datatable.getDefaultCell().setBorderWidth(2);
            datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

            // The header has the team name and the number of entries
            headerCell.setPhrase(new Phrase(t, headerFont));
            headerCell.setColspan(3);
            datatable.addCell(headerCell);

            headerCell.setPhrase(new Phrase(String.format("Entries : %d", count), headerFont));
            headerCell.setColspan(2);
            datatable.addCell(headerCell);

            datatable.setHeaderRows(1); // this is the end of the table header

            datatable.getDefaultCell().setBorderWidth(1);
            datatable.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);

            int i = 0;
            for (Wrestler w : wrestlers) {
                if ((i++ % 2) == 0) {
                    datatable.getDefaultCell().setGrayFill(0.9f);
                } else {
                    datatable.getDefaultCell().setGrayFill(1);
                }

                datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
                datatable.addCell(new Phrase(w.getFirstName(), detailFont));
                datatable.addCell(new Phrase(w.getLastName(), detailFont));
                datatable.addCell(new Phrase(w.getClassification(), detailFont));
                datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
                datatable.addCell(new Phrase(w.getAgeDivision(), detailFont));
                datatable.addCell(new Phrase(w.getWeightClass(), detailFont));
            }

            datatable.setSpacingBefore(5f);
            datatable.setSpacingAfter(15f);
            document.add(datatable);
        }

    } catch (DocumentException de) {
        logger.error("Document Exception", de);
        return false;
    }

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

    return true;
}

From source file:bouttime.report.weighin.WeighInReport.java

License:Open Source License

/**
 * Generate a report of the entries in the tournament for weigh-in.
 * @param sections List of sections for the report.  Each section will start
 *     on a new page.//from  ww w. j ava2 s. co  m
 * @param headerString String to be used for the header of each page of the report.
 * @return True if the report was generated.
 */
public static boolean doReport(List<List<Wrestler>> sections, String headerString) {
    // step 1: creation of a document-object
    Document document = new Document();

    try {

        // step 2: creation of the writer
        FileOutputStream fos = createOutputFile();
        if (fos == null) {
            return false;
        }
        PdfWriter.getInstance(document, fos);

        // step 3: we open the document
        document.open();

        // step 4: create and add content

        // create and add the header
        if (headerString != null) {
            Paragraph p1 = new Paragraph(
                    new Paragraph(headerString, FontFactory.getFont(FontFactory.HELVETICA, 10)));
            document.add(p1);
        }

        Font detailFont = new Font(Font.FontFamily.TIMES_ROMAN, 10);

        for (List<Wrestler> wrestlers : sections) {
            // create and add the table
            PdfPTable datatable = new PdfPTable(7);
            int colWidths[] = { 20, 20, 20, 10, 10, 10, 10 }; // percentage
            datatable.setWidths(colWidths);
            datatable.setWidthPercentage(100);
            datatable.getDefaultCell().setPadding(3);
            datatable.getDefaultCell().setBorderWidth(2);
            datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

            //datatable.setHeaderRows(1); // this is the end of the table header

            datatable.getDefaultCell().setBorderWidth(1);
            datatable.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);

            int i = 0;
            for (Wrestler w : wrestlers) {
                if ((i++ % 2) == 0) {
                    datatable.getDefaultCell().setGrayFill(0.9f);
                } else {
                    datatable.getDefaultCell().setGrayFill(1);
                }

                datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
                datatable.addCell(new Phrase(w.getLastName(), detailFont));
                datatable.addCell(new Phrase(w.getFirstName(), detailFont));
                datatable.addCell(new Phrase(w.getTeamName(), detailFont));
                datatable.addCell(new Phrase(w.getClassification(), detailFont));
                datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
                datatable.addCell(new Phrase(w.getAgeDivision(), detailFont));
                datatable.addCell(new Phrase(w.getWeightClass(), detailFont));
                datatable.addCell(new Phrase()); // actual weight
            }

            datatable.setSpacingBefore(5f);
            datatable.setSpacingAfter(15f);
            document.add(datatable);
            document.newPage();
        }

    } catch (DocumentException de) {
        logger.error("Document Exception", de);
        return false;
    }

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

    return true;
}

From source file:cimav.restrh.services.JustificacionREST.java

private Response tablaMercado(Integer id_param) {
    Justificacion justif = (Justificacion) JustificacionREST.this.find(id_param);

    StreamingOutput streamingOutput = new StreamingOutput() {
        public void write(OutputStream outputStream) throws IOException, WebApplicationException {

            try {
                //Create Document instance.
                Document document = new Document();
                PdfWriter.getInstance(document, outputStream);

                document.addAuthor("Generador adquisiciones | " + justif.getEmpleado().getCuentaCimav());
                String fileName1 = (justif.getRequisicion() + "-" + justif.getEmpleado().getCuentaCimav())
                        .replace(" ", "").replace(",", "");
                document.addTitle("Justificacin: " + fileName1);
                document.addSubject("Justificacin de Requisicin");

                document.open();/*w w w.  j  a  v a 2s .co m*/

                //Titulo del documento
                Paragraph parrafo = new Paragraph("Centro de Investigacin en Materiales Avanzados S. C.",
                        new Font(Font.FontFamily.TIMES_ROMAN, 17, Font.BOLD));
                parrafo.setAlignment(Element.ALIGN_CENTER);
                parrafo.setSpacingAfter(20);
                document.add(parrafo);

                PdfPTable table = new PdfPTable(3); // 3 columns.

                table.setWidths(new int[] { 30, 50, 100 });

                PdfPCell cell0 = new PdfPCell(
                        new Paragraph("Fecha:", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                PdfPCell cell1 = new PdfPCell(new Paragraph(
                        justif.getFechaInicio().getDayOfMonth() + " de "
                                + justif.getFechaInicio().getMonth().getDisplayName(TextStyle.FULL,
                                        new Locale("es", "ES"))
                                + " de " + justif.getFechaInicio().getYear(),
                        new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                PdfPCell cell2 = new PdfPCell(
                        new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                cell0.setBorder(PdfPCell.BOX);
                cell1.setBorder(PdfPCell.BOX);
                cell2.setBorder(PdfPCell.NO_BORDER);
                cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cell0);
                table.addCell(cell1);
                table.addCell(cell2);

                cell0 = new PdfPCell(new Paragraph("No. de Requisicin:",
                        new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                cell1 = new PdfPCell(new Paragraph(justif.getRequisicion(),
                        new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                cell2 = new PdfPCell(new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                cell0.setBorder(PdfPCell.BOX);
                cell1.setBorder(PdfPCell.BOX);
                cell2.setBorder(PdfPCell.NO_BORDER);
                cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cell0);
                table.addCell(cell1);
                table.addCell(cell2);

                cell0 = new PdfPCell(new Paragraph("Procedimiento:",
                        new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                cell1 = new PdfPCell(new Paragraph("Adjudicacin Directa",
                        new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                cell2 = new PdfPCell(new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                cell0.setBorder(PdfPCell.BOX);
                cell1.setBorder(PdfPCell.BOX);
                cell2.setBorder(PdfPCell.NO_BORDER);
                cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cell0);
                table.addCell(cell1);
                table.addCell(cell2);

                cell0 = new PdfPCell(new Paragraph("Origen de los bienes:",
                        new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                cell1 = new PdfPCell(new Paragraph(justif.esNacional(),
                        new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                cell2 = new PdfPCell(new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                cell0.setBorder(PdfPCell.BOX);
                cell1.setBorder(PdfPCell.BOX);
                cell2.setBorder(PdfPCell.NO_BORDER);
                cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cell0);
                table.addCell(cell1);
                table.addCell(cell2);

                document.add(table);

                parrafo = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                parrafo.setSpacingAfter(20);
                parrafo.setIndentationLeft(30);
                parrafo.setLeading(15);
                parrafo.setSpacingBefore(20);
                parrafo.setAlignment(Element.ALIGN_JUSTIFIED);
                document.add(parrafo);

                table = new PdfPTable(5);// 5 columns.
                table.setWidthPercentage(90); //table size %

                table.setWidths(new int[] { 'a', 'a', 'a', 'a', 'a' });

                cell0 = new PdfPCell(
                        new Paragraph("PARTIDA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD)));
                cell1 = new PdfPCell(
                        new Paragraph("DESCIPCIMAV", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD)));
                cell2 = new PdfPCell(
                        new Paragraph("PROVEEDOR No. 1", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD)));
                PdfPCell cell3 = new PdfPCell(
                        new Paragraph("PROVEEDOR No.2", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD)));
                PdfPCell cell4 = new PdfPCell(
                        new Paragraph("PROVEEDOR No.3", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD)));
                cell0.setBorder(PdfPCell.BOX);
                cell1.setBorder(PdfPCell.BOX);
                cell2.setBorder(PdfPCell.BOX);
                cell3.setBorder(PdfPCell.BOX);
                cell4.setBorder(PdfPCell.BOX);
                cell0.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell3.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell4.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cell0);
                table.addCell(cell1);
                table.addCell(cell2);
                table.addCell(cell3);
                table.addCell(cell4);

                cell0 = new PdfPCell(
                        new Paragraph("Partida #1", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD)));
                cell1 = new PdfPCell(new Paragraph(justif.getDescripcion(),
                        new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                cell0.setBorder(PdfPCell.BOX);
                cell1.setBorder(PdfPCell.BOX);
                cell0.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell0.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cell0.setRowspan(2);
                cell1.setRowspan(2);
                table.addCell(cell0);
                table.addCell(cell1);

                cell2 = new PdfPCell(new Paragraph(justif.getProveedorUno(),
                        new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                cell3 = new PdfPCell(new Paragraph(justif.getProveedorDos(),
                        new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                cell4 = new PdfPCell(new Paragraph(justif.getProveedorTres(),
                        new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                cell2.setBorder(PdfPCell.BOX);
                cell3.setBorder(PdfPCell.BOX);
                cell4.setBorder(PdfPCell.BOX);
                cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell3.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell4.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cell2);
                table.addCell(cell3);
                table.addCell(cell4);

                if (justif.getMontoUno() <= 1 && justif.getMontoDos() <= 1 && justif.getMontoTres() <= 1) {
                    cell2 = new PdfPCell(
                            new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                    cell3 = new PdfPCell(
                            new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                    cell4 = new PdfPCell(
                            new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));

                } else if (justif.getMontoUno() <= 1 && justif.getMontoDos() <= 1) {
                    cell2 = new PdfPCell(
                            new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                    cell3 = new PdfPCell(
                            new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                    cell4 = new PdfPCell(new Paragraph(montoFormatComas(justif.getMontoTres(), justif),
                            new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));

                } else if (justif.getMontoUno() <= 1 && justif.getMontoTres() <= 1) {
                    cell2 = new PdfPCell(
                            new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                    cell3 = new PdfPCell(new Paragraph(montoFormatComas(justif.getMontoDos(), justif),
                            new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                    cell4 = new PdfPCell(
                            new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));

                } else if (justif.getMontoDos() <= 1 && justif.getMontoTres() <= 1) {
                    cell2 = new PdfPCell(new Paragraph(montoFormatComas(justif.getMontoUno(), justif),
                            new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                    cell3 = new PdfPCell(
                            new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                    cell4 = new PdfPCell(
                            new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));

                } else if (justif.getMontoUno() <= 1) {
                    cell2 = new PdfPCell(
                            new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                    cell3 = new PdfPCell(new Paragraph(montoFormatComas(justif.getMontoDos(), justif),
                            new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                    cell4 = new PdfPCell(new Paragraph(montoFormatComas(justif.getMontoTres(), justif),
                            new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));

                } else if (justif.getMontoDos() <= 1) {
                    cell2 = new PdfPCell(new Paragraph(
                            "Subtotal: " + justif.getSubTotal() + "\n" + "IVA: " + justif.getIva() + "\n"
                                    + "Total:" + "\n" + montoFormatComas(justif.getImporte(), justif),
                            new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                    cell3 = new PdfPCell(
                            new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                    cell4 = new PdfPCell(new Paragraph(montoFormatComas(justif.getMontoTres(), justif),
                            new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));

                } else if (justif.getMontoTres() <= 1) {
                    cell2 = new PdfPCell(new Paragraph(
                            "Subtotal: " + justif.getSubTotal() + "\n" + "IVA: " + justif.getIva() + "\n"
                                    + "Total:" + "\n" + montoFormatComas(justif.getImporte(), justif),
                            new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                    cell3 = new PdfPCell(new Paragraph(montoFormatComas(justif.getMontoDos(), justif),
                            new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                    cell4 = new PdfPCell(
                            new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                } else {
                    cell2 = new PdfPCell(new Paragraph(
                            "Subtotal: " + justif.getSubTotal() + "\n" + "IVA: " + justif.getIva() + "\n"
                                    + "Total:" + "\n" + montoFormatComas(justif.getImporte(), justif),
                            new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                    cell3 = new PdfPCell(new Paragraph(montoFormatComas(justif.getMontoDos(), justif),
                            new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                    cell4 = new PdfPCell(new Paragraph(montoFormatComas(justif.getMontoTres(), justif),
                            new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                }
                cell2.setBorder(PdfPCell.BOX);
                cell3.setBorder(PdfPCell.BOX);
                cell4.setBorder(PdfPCell.BOX);
                cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell2.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cell3.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell3.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cell4.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell4.setVerticalAlignment(Element.ALIGN_MIDDLE);
                table.addCell(cell2);
                table.addCell(cell3);
                table.addCell(cell4);
                document.add(table);

                parrafo = new Paragraph(
                        "Tal como lo establece el artculo 29 " + "del Reglamento de la Ley de Adquisiciones, "
                                + "Arrendamientos y Servicios del Sector Pblico,"
                                + " la investigacin de mercado arrojo los siguientes resultados:\n",
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                parrafo.setSpacingAfter(20);
                parrafo.setIndentationLeft(30);
                parrafo.setLeading(15);
                parrafo.setSpacingBefore(10);
                parrafo.setAlignment(Element.ALIGN_JUSTIFIED);
                document.add(parrafo);

                parrafo = new Paragraph(
                        "Fraccin I, determinamos la existencia de oferta de los bienes requeridos.\n"
                                + "Fraccin II, verificamos existencias de los mismos con los proveedores que nos proporcionaron cotizacin formal.\n"
                                + "Fraccin III, conocimos los precios que prevalecan en el mercado nacional.\n",
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));

                parrafo.setIndentationLeft(50);
                parrafo.setLeading(15);
                parrafo.setAlignment(Element.ALIGN_JUSTIFIED);
                document.add(parrafo);

                parrafo = new Paragraph(
                        "A travs de la investigacin de mercado realizada, "
                                + "concluimos que la mejor opcin de compra es la oferta del proveedor" + " "
                                + justif.getProveedorUno(),
                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
                parrafo.setSpacingAfter(10);
                parrafo.setIndentationLeft(30);
                parrafo.setLeading(15);
                parrafo.setSpacingBefore(20);
                parrafo.setAlignment(Element.ALIGN_JUSTIFIED);
                document.add(parrafo);

                document.close();
                outputStream.close();

            } catch (DocumentException ex) {
                Logger.getLogger(JustificacionREST.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
    };
    ResponseBuilder response = Response.ok(streamingOutput);
    String fileName = ("inline; filename=" + justif.getRequisicion() + "-"
            + justif.getEmpleado().getCuentaCimav() + ".pdf").replace(" ", "").replace(",", "-");
    response.header("Content-Disposition", fileName);

    return response.build();
}

From source file:cn.afterturn.easypoi.pdf.styler.PdfExportStylerDefaultImpl.java

License:Apache License

@Override
public void setCellStyler(PdfPCell iCell, ExcelExportEntity entity, String text) {
    iCell.setHorizontalAlignment(Element.ALIGN_CENTER);
    iCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
}

From source file:com.etest.pdfgenerator.InventoryCasesReportPDF.java

public InventoryCasesReportPDF() {
    Document document = null;//w  ww .j  a v  a 2 s.c  o m
    Date date = new Date();

    try {
        document = new Document(PageSize.LETTER, 50, 50, 50, 50);
        PdfWriter.getInstance(document, outputStream);
        document.open();

        Font header = FontFactory.getFont("Times-Roman", 12, Font.BOLD);
        Font content = FontFactory.getFont("Times-Roman", 10);
        Font dateFont = FontFactory.getFont("Times-Roman", 8);

        Image img = null;
        try {
            img = Image.getInstance("C:\\eTest-images\\SUCN_seal.png");
            img.scaleToFit(60, 60);
            img.setAbsolutePosition(500, 700);
        } catch (BadElementException | IOException ex) {
            Logger.getLogger(TQCoveragePDF.class.getName()).log(Level.SEVERE, null, ex);
        }
        document.add(img);

        Paragraph reportTitle = new Paragraph();
        reportTitle.setAlignment(Element.ALIGN_CENTER);
        reportTitle.add(new Phrase("Inventory of Cases Report", header));
        document.add(reportTitle);

        Paragraph datePrinted = new Paragraph();
        datePrinted.setSpacingAfter(20f);
        datePrinted.setAlignment(Element.ALIGN_CENTER);
        datePrinted.add(
                new Phrase("Date printed: " + new SimpleDateFormat("dd MMMM yyyy").format(date), dateFont));
        document.add(datePrinted);

        PdfPTable table = new PdfPTable(4);
        table.setWidthPercentage(100);
        table.setWidths(new int[] { 100, 300, 100, 100 });
        table.setSpacingAfter(5f);

        PdfPCell cellOne = new PdfPCell(new Phrase("Subject"));
        cellOne.setBorder(Rectangle.NO_BORDER);
        cellOne.setPaddingLeft(10);
        cellOne.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
        cellOne.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellTwo = new PdfPCell(new Phrase("Descriptive Title"));
        cellTwo.setBorder(Rectangle.NO_BORDER);
        cellTwo.setPaddingLeft(10);
        cellTwo.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
        cellTwo.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellThree = new PdfPCell(new Phrase("No. of Cases"));
        cellThree.setBorder(Rectangle.NO_BORDER);
        cellThree.setPaddingLeft(10);
        cellThree.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellThree.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellFour = new PdfPCell(new Phrase("No. of Items"));
        cellFour.setBorder(Rectangle.NO_BORDER);
        cellFour.setPaddingLeft(10);
        cellFour.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellFour.setVerticalAlignment(Element.ALIGN_MIDDLE);

        table.addCell(cellOne);
        table.addCell(cellTwo);
        table.addCell(cellThree);
        table.addCell(cellFour);

        table.getDefaultCell().setBorderWidth(0f);
        document.add(table);

        for (InventoryOfCasesReport report : service.getInventoryOfCases()) {
            PdfPTable table2 = new PdfPTable(4);
            table2.setWidthPercentage(100);
            table2.setWidths(new int[] { 100, 300, 100, 100 });
            table2.setSpacingBefore(3f);
            table2.setSpacingAfter(3f);

            if (!service.getListOfSyllabusIdByCurriculumId(report.getCurriculumId()).isEmpty()) {
                if (!service
                        .getListOfCellCaseIdBySyllabusId(
                                service.getListOfSyllabusIdByCurriculumId(report.getCurriculumId()))
                        .isEmpty()) {
                    PdfPCell cell1 = new PdfPCell(new Paragraph(report.getSubject(), content));
                    cell1.setBorder(0);
                    cell1.setPaddingLeft(10);
                    cell1.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
                    cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);

                    PdfPCell cell2 = new PdfPCell(new Paragraph(report.getDescriptiveTitle(), content));
                    cell2.setBorder(0);
                    cell2.setPaddingLeft(10);
                    cell2.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
                    cell2.setVerticalAlignment(Element.ALIGN_MIDDLE);

                    PdfPCell cell3 = new PdfPCell(new Paragraph(
                            String.valueOf(service.getTotalCellCasesBySyllabus(
                                    service.getListOfSyllabusIdByCurriculumId(report.getCurriculumId()))),
                            content));
                    cell3.setBorder(0);
                    cell3.setPaddingLeft(10);
                    cell3.setHorizontalAlignment(Element.ALIGN_CENTER);
                    cell3.setVerticalAlignment(Element.ALIGN_MIDDLE);

                    PdfPCell cell4 = new PdfPCell(new Paragraph(
                            String.valueOf(service.getTotalCellItemsByCellCaseId(
                                    service.getListOfCellCaseIdBySyllabusId(service
                                            .getListOfSyllabusIdByCurriculumId(report.getCurriculumId())))),
                            content));
                    cell4.setBorder(0);
                    cell4.setPaddingLeft(10);
                    cell4.setHorizontalAlignment(Element.ALIGN_CENTER);
                    cell4.setVerticalAlignment(Element.ALIGN_MIDDLE);

                    table2.addCell(cell1);
                    table2.addCell(cell2);
                    table2.addCell(cell3);
                    table2.addCell(cell4);
                    document.add(table2);
                }
            }
        }
    } catch (DocumentException ex) {
        Logger.getLogger(InventoryItemsReportPDF.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        document.close();
    }
}

From source file:com.etest.pdfgenerator.InventoryItemsReportPDF.java

public InventoryItemsReportPDF() {
    Document document = null;/*from  w  w w .  j av  a2s .c  om*/
    Date date = new Date();

    try {
        document = new Document(PageSize.LETTER.rotate(), 50, 50, 50, 50);
        PdfWriter.getInstance(document, outputStream);
        document.open();

        Font header = FontFactory.getFont("Times-Roman", 12, Font.BOLD);
        Font content = FontFactory.getFont("Times-Roman", 10);
        Font dateFont = FontFactory.getFont("Times-Roman", 8);

        Image img = null;
        try {
            img = Image.getInstance("C:\\eTest-images\\SUCN_seal.png");
            img.scaleToFit(60, 60);
            img.setAbsolutePosition(650, 500);
        } catch (BadElementException | IOException ex) {
            Logger.getLogger(TQCoveragePDF.class.getName()).log(Level.SEVERE, null, ex);
        }
        document.add(img);

        Paragraph title1 = new Paragraph();
        title1.setAlignment(Element.ALIGN_CENTER);
        title1.add(new Phrase("Inventory of Items Report"));
        document.add(title1);

        Paragraph title2 = new Paragraph();
        title2.setAlignment(Element.ALIGN_CENTER);
        title2.add(new Phrase("Grouped According to the Revised Bloom's Taxonomy"));
        document.add(title2);

        Paragraph datePrinted = new Paragraph();
        datePrinted.setSpacingAfter(20f);
        datePrinted.setAlignment(Element.ALIGN_CENTER);
        datePrinted
                .add(new Phrase("Date printed: " + new SimpleDateFormat("dd MMMM yyyy").format(date), content));
        document.add(datePrinted);

        PdfPTable table = new PdfPTable(8);
        table.setWidthPercentage(100);
        table.setSpacingAfter(5f);

        for (int i = 0; i < tableHeader.length; i++) {
            PdfPCell cell = new PdfPCell(new Phrase(tableHeader[i], header));
            cell.setBorder(Rectangle.NO_BORDER);
            cell.setPaddingLeft(10);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            if (tableHeader[i].equals("Subject")) {
                cell.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
            } else {
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            }
            table.addCell(cell);
        }

        document.add(table);

        for (InventoryOfCasesReport report : service.getInventoryOfCases()) {
            PdfPTable table2 = new PdfPTable(8);
            table2.setWidthPercentage(100);
            table2.setSpacingBefore(3f);
            table2.setSpacingAfter(3f);

            if (!service.getListOfSyllabusIdByCurriculumId(report.getCurriculumId()).isEmpty()) {
                if (!service
                        .getListOfCellCaseIdBySyllabusId(
                                service.getListOfSyllabusIdByCurriculumId(report.getCurriculumId()))
                        .isEmpty()) {
                    PdfPCell cell1 = new PdfPCell(new Paragraph(report.getSubject(), content));
                    cell1.setBorder(0);
                    cell1.setPaddingLeft(10);
                    cell1.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
                    cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);

                    PdfPCell cell2 = new PdfPCell(
                            new Paragraph(String.valueOf(service.getTotalItemsByBloomsTaxonomy(
                                    service.getListOfCellCaseIdBySyllabusId(service
                                            .getListOfSyllabusIdByCurriculumId(report.getCurriculumId())),
                                    tq.getBloomsClassId(BloomsClass.Remember.toString()))), content));
                    cell2.setBorder(0);
                    cell2.setPaddingLeft(10);
                    cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
                    cell2.setVerticalAlignment(Element.ALIGN_MIDDLE);

                    PdfPCell cell3 = new PdfPCell(
                            new Paragraph(String.valueOf(service.getTotalItemsByBloomsTaxonomy(
                                    service.getListOfCellCaseIdBySyllabusId(service
                                            .getListOfSyllabusIdByCurriculumId(report.getCurriculumId())),
                                    tq.getBloomsClassId(BloomsClass.Understand.toString()))), content));
                    cell3.setBorder(0);
                    cell3.setPaddingLeft(10);
                    cell3.setHorizontalAlignment(Element.ALIGN_CENTER);
                    cell3.setVerticalAlignment(Element.ALIGN_MIDDLE);

                    PdfPCell cell4 = new PdfPCell(
                            new Paragraph(String.valueOf(service.getTotalItemsByBloomsTaxonomy(
                                    service.getListOfCellCaseIdBySyllabusId(service
                                            .getListOfSyllabusIdByCurriculumId(report.getCurriculumId())),
                                    tq.getBloomsClassId(BloomsClass.Apply.toString()))), content));
                    cell4.setBorder(0);
                    cell4.setPaddingLeft(10);
                    cell4.setHorizontalAlignment(Element.ALIGN_CENTER);
                    cell4.setVerticalAlignment(Element.ALIGN_MIDDLE);

                    PdfPCell cell5 = new PdfPCell(
                            new Paragraph(String.valueOf(service.getTotalItemsByBloomsTaxonomy(
                                    service.getListOfCellCaseIdBySyllabusId(service
                                            .getListOfSyllabusIdByCurriculumId(report.getCurriculumId())),
                                    tq.getBloomsClassId(BloomsClass.Analyze.toString()))), content));
                    cell5.setBorder(0);
                    cell5.setPaddingLeft(10);
                    cell5.setHorizontalAlignment(Element.ALIGN_CENTER);
                    cell5.setVerticalAlignment(Element.ALIGN_MIDDLE);

                    PdfPCell cell6 = new PdfPCell(
                            new Paragraph(String.valueOf(service.getTotalItemsByBloomsTaxonomy(
                                    service.getListOfCellCaseIdBySyllabusId(service
                                            .getListOfSyllabusIdByCurriculumId(report.getCurriculumId())),
                                    tq.getBloomsClassId(BloomsClass.Evaluate.toString()))), content));
                    cell6.setBorder(0);
                    cell6.setPaddingLeft(10);
                    cell6.setHorizontalAlignment(Element.ALIGN_CENTER);
                    cell6.setVerticalAlignment(Element.ALIGN_MIDDLE);

                    PdfPCell cell7 = new PdfPCell(
                            new Paragraph(String.valueOf(service.getTotalItemsByBloomsTaxonomy(
                                    service.getListOfCellCaseIdBySyllabusId(service
                                            .getListOfSyllabusIdByCurriculumId(report.getCurriculumId())),
                                    tq.getBloomsClassId(BloomsClass.Create.toString()))), content));
                    cell7.setBorder(0);
                    cell7.setPaddingLeft(10);
                    cell7.setHorizontalAlignment(Element.ALIGN_CENTER);
                    cell7.setVerticalAlignment(Element.ALIGN_MIDDLE);

                    PdfPCell cell8 = new PdfPCell(new Paragraph(
                            String.valueOf(service.getTotalCellItemsByCellCaseId(
                                    service.getListOfCellCaseIdBySyllabusId(service
                                            .getListOfSyllabusIdByCurriculumId(report.getCurriculumId())))),
                            content));
                    cell8.setBorder(0);
                    cell8.setPaddingLeft(10);
                    cell8.setHorizontalAlignment(Element.ALIGN_CENTER);
                    cell8.setVerticalAlignment(Element.ALIGN_MIDDLE);

                    table2.addCell(cell1);
                    table2.addCell(cell2);
                    table2.addCell(cell3);
                    table2.addCell(cell4);
                    table2.addCell(cell5);
                    table2.addCell(cell6);
                    table2.addCell(cell7);
                    table2.addCell(cell8);
                    document.add(table2);
                }
            }
        }
    } catch (DocumentException ex) {
        Logger.getLogger(InventoryItemsReportPDF.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        document.close();
    }
}

From source file:com.etest.pdfgenerator.ItemAnalysisOfSubjectReportPDF.java

public ItemAnalysisOfSubjectReportPDF(int curriculumId) {
    this.curriculumId = curriculumId;

    Document document = null;// w  w w.j a  v  a2  s .  c o  m

    try {
        document = new Document(PageSize.A4, 50, 50, 50, 50);
        PdfWriter.getInstance(document, outputStream);
        document.open();

        Font header1 = FontFactory.getFont("Times-Roman", 14, Font.BOLD);
        Font header2 = FontFactory.getFont("Times-Roman", 12, Font.BOLD);
        Font content = FontFactory.getFont("Times-Roman", 10);

        Paragraph title1 = new Paragraph();
        title1.setSpacingAfter(10f);
        title1.setAlignment(Element.ALIGN_CENTER);
        title1.add(new Phrase("Interactive Querying", header1));
        document.add(title1);

        Paragraph title2 = new Paragraph();
        title2.setSpacingAfter(10f);
        title2.setAlignment(Element.ALIGN_CENTER);
        title2.add(new Phrase("View Item Analysis of a Subject", content));
        document.add(title2);

        Paragraph subject = new Paragraph();
        subject.setAlignment(Element.ALIGN_LEFT);
        subject.add(new Phrase("Subject: " + cs.getCurriculumById(getCurriculumId()).getSubject().toUpperCase(),
                content));
        document.add(subject);

        Paragraph descriptiveTitle = new Paragraph();
        descriptiveTitle.setAlignment(Element.ALIGN_LEFT);
        descriptiveTitle.add(new Phrase(
                "Descriptive Title: " + cs.getCurriculumById(getCurriculumId()).getDescriptiveTitle(),
                content));
        document.add(descriptiveTitle);

        Paragraph term = new Paragraph();
        term.setSpacingAfter(20f);
        term.setAlignment(Element.ALIGN_LEFT);
        term.add(new Phrase("Normal Course Offering: 2nd Semester", content));
        document.add(term);

        PdfPTable table = new PdfPTable(2);
        table.setWidthPercentage(75);

        PdfPCell cellOne = new PdfPCell(new Phrase("Difficulty"));
        cellOne.setBorder(0);
        cellOne.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellOne.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellTwo = new PdfPCell(new Phrase("Discrimination"));
        cellTwo.setBorder(0);
        cellTwo.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellTwo.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellThree = new PdfPCell(new Phrase(String
                .valueOf(rs.getIndexesOfAllTestForASubject(getCurriculumId(), "DifficultIndex", 0.00, 0.19))
                + " Very difficult item(s)", content));
        cellThree.setBorder(0);
        cellThree.setPaddingLeft(50);
        cellThree.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
        cellThree.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellFour = new PdfPCell(new Phrase(String.valueOf(
                rs.getIndexesOfAllTestForASubject(getCurriculumId(), "DiscriminationIndex", 0.00, 0.19))
                + " Poor items(s)", content));
        cellFour.setBorder(0);
        cellFour.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellFour.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellFive = new PdfPCell(new Phrase(String
                .valueOf(rs.getIndexesOfAllTestForASubject(getCurriculumId(), "DifficultIndex", 0.20, 0.39))
                + " difficult item(s)", content));
        cellFive.setBorder(0);
        cellFive.setPaddingLeft(50);
        cellFive.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
        cellFive.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellSix = new PdfPCell(new Phrase(String.valueOf(
                rs.getIndexesOfAllTestForASubject(getCurriculumId(), "DiscriminationIndex", 0.20, 0.29))
                + " Marginal items(s)", content));
        cellSix.setBorder(0);
        cellSix.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellSix.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellSeven = new PdfPCell(new Phrase(String
                .valueOf(rs.getIndexesOfAllTestForASubject(getCurriculumId(), "DifficultIndex", 0.40, 0.60))
                + " Average item(s)", content));
        cellSeven.setBorder(0);
        cellSeven.setPaddingLeft(50);
        cellSeven.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
        cellSeven.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellEight = new PdfPCell(new Phrase(String.valueOf(
                rs.getIndexesOfAllTestForASubject(getCurriculumId(), "DiscriminationIndex", 0.30, 0.39))
                + " Reasonably Good items(s)", content));
        cellEight.setBorder(0);
        cellEight.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellEight.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellNine = new PdfPCell(new Phrase(String
                .valueOf(rs.getIndexesOfAllTestForASubject(getCurriculumId(), "DifficultIndex", 0.61, 0.80))
                + " Easy item(s)", content));
        cellNine.setBorder(0);
        cellNine.setPaddingLeft(50);
        cellNine.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
        cellNine.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellTen = new PdfPCell(new Phrase(String
                .valueOf(rs.getIndexesOfAllTestForASubject(getCurriculumId(), "DiscriminationIndex", 0.41, 1))
                + " Very good items(s)", content));
        cellTen.setBorder(0);
        cellTen.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellTen.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellEleven = new PdfPCell(new Phrase(
                String.valueOf(rs.getIndexesOfAllTestForASubject(getCurriculumId(), "DifficultIndex", 0.81, 1))
                        + " Very Easy item(s)",
                content));
        cellEleven.setBorder(0);
        cellEleven.setPaddingLeft(50);
        cellEleven.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
        cellEleven.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellTwelve = new PdfPCell(new Phrase(""));
        cellTwelve.setBorder(0);
        cellTwelve.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellTwelve.setVerticalAlignment(Element.ALIGN_MIDDLE);

        table.addCell(cellOne);
        table.addCell(cellTwo);
        table.addCell(cellThree);
        table.addCell(cellFour);
        table.addCell(cellFive);
        table.addCell(cellSix);
        table.addCell(cellSeven);
        table.addCell(cellEight);
        table.addCell(cellNine);
        table.addCell(cellTen);
        table.addCell(cellEleven);
        table.addCell(cellTwelve);

        document.add(table);
    } catch (DocumentException ex) {
        Logger.getLogger(ItemAnalysisOfSubjectReportPDF.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        if (document != null) {
            document.close();
        }
    }
}

From source file:com.etest.pdfgenerator.ItemAnalysisReportPDF.java

public ItemAnalysisReportPDF(int tqCoverageId) {
    this.tqCoverageId = tqCoverageId;

    Document document = null;//from ww  w .  ja  va2 s  .  c o  m
    Date date = new Date();

    try {
        document = new Document(PageSize.A4, 50, 50, 50, 50);
        PdfWriter.getInstance(document, outputStream);
        document.open();

        Font header = FontFactory.getFont("Times-Roman", 12, Font.BOLD);
        Font content = FontFactory.getFont("Times-Roman", 10);
        Font dateFont = FontFactory.getFont("Times-Roman", 8);

        Image img = null;
        try {
            img = Image.getInstance("C:\\eTest-images\\SUCN_seal.png");
            img.scaleToFit(60, 60);
            img.setAbsolutePosition(450, 730);
        } catch (BadElementException | IOException ex) {
            Logger.getLogger(TQCoveragePDF.class.getName()).log(Level.SEVERE, null, ex);
        }
        document.add(img);

        Paragraph reportTitle = new Paragraph();
        reportTitle.setAlignment(Element.ALIGN_CENTER);
        reportTitle.add(new Phrase("Item Analysis Report", header));
        document.add(reportTitle);

        Paragraph datePrinted = new Paragraph();
        datePrinted.setSpacingAfter(20f);
        datePrinted.setAlignment(Element.ALIGN_CENTER);
        datePrinted.add(
                new Phrase("Date printed: " + new SimpleDateFormat("dd MMMM yyyy").format(date), dateFont));
        document.add(datePrinted);

        Paragraph subject = new Paragraph();
        subject.setAlignment(Element.ALIGN_LEFT);
        subject.add(new Phrase(
                "Subject: " + cs.getCurriculumById(tq.getTQCoverageById(getTqCoverageId()).getCurriculumId())
                        .getSubject().toUpperCase(),
                content));
        document.add(subject);

        Paragraph term = new Paragraph();
        term.setAlignment(Element.ALIGN_LEFT);
        term.add(new Phrase("SY and Semester Administered: 2015-16 2nd Semester", content));
        document.add(term);

        Paragraph type = new Paragraph();
        type.setSpacingAfter(20f);
        type.setAlignment(Element.ALIGN_LEFT);
        type.add(
                new Phrase("Type of Test: " + tq.getTQCoverageById(getTqCoverageId()).getExamTitle(), content));
        document.add(type);

        PdfPTable table = new PdfPTable(5);
        table.setWidthPercentage(100);
        table.setWidths(new int[] { 130, 300, 300, 300, 300 });
        //            table.setSpacingAfter(5f);             

        PdfPCell cellOne = new PdfPCell(new Phrase("Item No."));
        cellOne.setBorderWidthTop(1);
        cellOne.setBorderWidthLeft(1);
        cellOne.setBorderWidthRight(1);
        cellOne.setBorderWidthBottom(1);
        cellOne.setPaddingLeft(10);
        cellOne.setPaddingRight(10);
        cellOne.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
        cellOne.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellTwo = new PdfPCell(new Phrase("Difficulty"));
        cellTwo.setBorderWidthTop(1);
        cellTwo.setBorderWidthLeft(1);
        cellTwo.setBorderWidthRight(1);
        cellTwo.setBorderWidthBottom(1);
        cellTwo.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellTwo.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellThree = new PdfPCell(new Phrase("Interpretation"));
        cellThree.setBorderWidthTop(1);
        cellThree.setBorderWidthLeft(1);
        cellThree.setBorderWidthRight(1);
        cellThree.setBorderWidthBottom(1);
        cellThree.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellThree.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellFour = new PdfPCell(new Phrase("Discrimination"));
        cellFour.setBorderWidthTop(1);
        cellFour.setBorderWidthLeft(1);
        cellFour.setBorderWidthRight(1);
        cellFour.setBorderWidthBottom(1);
        cellFour.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellFour.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellFive = new PdfPCell(new Phrase("Interpretation"));
        cellFive.setBorderWidthTop(1);
        cellFive.setBorderWidthLeft(1);
        cellFive.setBorderWidthRight(1);
        cellFive.setBorderWidthBottom(1);
        cellFive.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellFive.setVerticalAlignment(Element.ALIGN_MIDDLE);

        table.addCell(cellOne);
        table.addCell(cellTwo);
        table.addCell(cellThree);
        table.addCell(cellFour);
        table.addCell(cellFive);

        table.getDefaultCell().setBorderWidth(0f);
        document.add(table);

        PdfPTable table2 = new PdfPTable(5);
        table2.setWidthPercentage(100);
        table2.setWidths(new int[] { 130, 300, 300, 300, 300 });

        int itemNo = 1;
        for (CellItem ci : cis.getItemAnalysisResult(tqCoverageId)) {
            PdfPCell cell1 = new PdfPCell(new Paragraph(String.valueOf(itemNo), content));
            cell1.setBorderWidthTop(1);
            cell1.setBorderWidthLeft(1);
            cell1.setBorderWidthRight(1);
            cell1.setBorderWidthBottom(1);
            cell1.setPaddingLeft(10);
            cell1.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
            cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);

            PdfPCell cell2 = new PdfPCell(new Paragraph(String.valueOf(ci.getDifficultIndex()), content));
            cell2.setBorderWidthTop(1);
            cell2.setBorderWidthLeft(1);
            cell2.setBorderWidthRight(1);
            cell2.setBorderWidthBottom(1);
            cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell2.setVerticalAlignment(Element.ALIGN_MIDDLE);

            PdfPCell cell3 = new PdfPCell(new Paragraph(
                    ItemAnalysisInterpretation.getDifficultyInterpretation(ci.getDifficultIndex()), content));
            cell3.setBorderWidthTop(1);
            cell3.setBorderWidthLeft(1);
            cell3.setBorderWidthRight(1);
            cell3.setBorderWidthBottom(1);
            cell3.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell3.setVerticalAlignment(Element.ALIGN_MIDDLE);

            PdfPCell cell4 = new PdfPCell(new Paragraph(String.valueOf(ci.getDiscriminationIndex()), content));
            cell4.setBorderWidthTop(1);
            cell4.setBorderWidthLeft(1);
            cell4.setBorderWidthRight(1);
            cell4.setBorderWidthBottom(1);
            cell4.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell4.setVerticalAlignment(Element.ALIGN_MIDDLE);

            PdfPCell cell5 = new PdfPCell(new Paragraph(
                    ItemAnalysisInterpretation.getDiscriminationInterpretation(ci.getDiscriminationIndex()),
                    content));
            cell5.setBorderWidthTop(1);
            cell5.setBorderWidthLeft(1);
            cell5.setBorderWidthRight(1);
            cell5.setBorderWidthBottom(1);
            cell5.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell5.setVerticalAlignment(Element.ALIGN_MIDDLE);

            table2.addCell(cell1);
            table2.addCell(cell2);
            table2.addCell(cell3);
            table2.addCell(cell4);
            table2.addCell(cell5);

            itemNo++;
        }
        table.getDefaultCell().setBorderWidth(0f);
        document.add(table2);

    } catch (DocumentException ex) {
        Logger.getLogger(ItemAnalysisReportPDF.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        document.close();
    }
}