Example usage for com.itextpdf.text Font Font

List of usage examples for com.itextpdf.text Font Font

Introduction

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

Prototype


public Font(final FontFamily family, final float size, final int style) 

Source Link

Document

Constructs a Font.

Usage

From source file:edu.harvard.mcz.precapture.ui.ContainerLabel.java

License:Open Source License

/**
 * /*from   w ww .j  a va2  s. c o  m*/
 * @return a PDF paragraph cell containing a text encoding of the fields in this set.
 */
public PdfPCell toPDFCell(LabelDefinitionType printDefinition) {
    PdfPCell cell = new PdfPCell();
    ;
    if (printDefinition.getTextOrentation().toString().toLowerCase()
            .equals(TextOrentationType.VERTICAL.toString().toLowerCase())) {
        log.debug("Print orientation of text is Vertical");
        cell.setRotation(90);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
    }
    cell.setBorderColor(BaseColor.LIGHT_GRAY);
    cell.setVerticalAlignment(PdfPCell.ALIGN_TOP);
    cell.disableBorderSide(PdfPCell.RIGHT);
    cell.setPaddingLeft(3);
    cell.setNoWrap(false);

    int leading = (int) (fields.get(0).getField().getFontSize() + printDefinition.getFontDelta()) - 1;
    Paragraph higher = new Paragraph(leading, "", new Font(Font.FontFamily.TIMES_ROMAN,
            fields.get(0).getField().getFontSize() + printDefinition.getFontDelta(), Font.NORMAL));
    higher.setSpacingBefore(0);
    higher.setSpacingAfter(0);
    boolean added = false;
    boolean hasContent = false;
    for (int i = 0; i < fields.size(); i++) {
        log.debug(i);
        if (fields.get(i).getField().isNewLine() || (i == fields.size() - 1)) {
            if (!higher.isEmpty()) {
                log.debug(higher.getContent());
                cell.addElement(higher);
            }
            leading = (int) (fields.get(i).getField().getFontSize() + printDefinition.getFontDelta()) - 1;
            higher = new Paragraph(leading, "", new Font(Font.FontFamily.TIMES_ROMAN,
                    fields.get(i).getField().getFontSize() + printDefinition.getFontDelta(), Font.NORMAL));
            higher.setSpacingBefore(0);
            higher.setSpacingAfter(0);
            added = false;
            hasContent = false;
        }
        log.debug(fields.get(i).getTextField().getText().trim());
        Chunk chunk = new Chunk(fields.get(i).getTextField().getText().trim());
        if (fields.get(i).getField().isUseItalic()) {
            chunk.setFont(new Font(Font.FontFamily.TIMES_ROMAN,
                    fields.get(i).getField().getFontSize() + printDefinition.getFontDelta(), Font.ITALIC));
        } else {
            chunk.setFont(new Font(Font.FontFamily.TIMES_ROMAN,
                    fields.get(i).getField().getFontSize() + printDefinition.getFontDelta(), Font.NORMAL));
        }
        if (!chunk.isEmpty()) {
            hasContent = true;
            higher.add(chunk);
            log.debug(fields.get(i).getField().getSuffix());
            if (fields.get(i).getField().getSuffix() != null
                    && fields.get(i).getField().getSuffix().length() > 0) {
                higher.add(new Chunk(fields.get(i).getField().getSuffix()));
            }
            if (fields.get(i).getTextField().getText().trim().length() > 0) {
                // add a trailing space as a separator if there was something to separate.
                higher.add(new Chunk(" "));
            }
        }
    }
    if (!added) {
        log.debug(higher.getContent());
        cell.addElement(higher);
    }
    String extraText = PreCaptureSingleton.getInstance().getProperties().getProperties()
            .getProperty(PreCaptureProperties.KEY_EXTRAHUMANTEXT);
    if (extraText != null && extraText.length() > 0) {
        log.debug(extraText);
        cell.addElement(new Chunk(extraText));
    }

    return cell;
}

From source file:es.sm2.openppm.front.utils.DocumentUtils.java

License:Open Source License

/**
 * Create PDF for Control Change//from   ww w. j a v  a  2s .c o m
 * @param idioma
 * @param project
 * @param change
 * @param preparedBy
 * @return
 * @throws DocumentException
 * @throws LogicException
 */
public static byte[] toPdf(ResourceBundle idioma, Project project, Changecontrol change, Employee preparedBy,
        final Image headerImg, final Image footerImg) throws DocumentException, LogicException {

    if (change == null) {
        throw new DocumentException("No change control found.");
    }

    if (preparedBy == null || preparedBy.getContact() == null) {
        throw new UserSendingException();
    }

    Document document = new Document(PageSize.A4);
    document.setMargins(70F, 70F, 38F, 38F); // Total Height: 842pt, Total Width: 595pt
    byte[] file = null;

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    @SuppressWarnings("unused")
    PdfWriter pdfWriter = PdfWriter.getInstance(document, outputStream);

    document.open();

    Font fontHeader = new Font(FontFamily.TIMES_ROMAN, 9, Font.BOLD);
    Font fontCell = new Font(FontFamily.TIMES_ROMAN, 9);
    Font tituloFont = new Font(FontFamily.TIMES_ROMAN, 16, Font.BOLD);

    document.add(new Paragraph(" ", tituloFont));
    document.add(new Paragraph(" ", tituloFont));
    document.add(new Paragraph(" ", fontHeader));
    Paragraph title = new Paragraph(idioma.getString("change_request").toUpperCase(), tituloFont);
    title.setAlignment(Paragraph.ALIGN_CENTER);
    document.add(title);

    // Header Table
    // Project info
    PdfPTable tableHeader = new PdfPTable(3);
    tableHeader.setWidthPercentage(100);
    tableHeader.setSpacingBefore(10);
    tableHeader.setSpacingAfter(15);

    int[] colWidth = new int[3];
    colWidth[0] = 40;
    colWidth[1] = 30;
    colWidth[2] = 30;
    tableHeader.setWidths(colWidth);

    tableHeader.addCell(
            prepareHeaderCell(idioma.getString("change_request.project_name"), fontHeader, 1F, 0F, 0F, 1F));
    tableHeader.addCell(
            prepareHeaderCell(idioma.getString("change_request.prepared_by"), fontHeader, 1F, 0F, 0F, 1F));
    tableHeader.addCell(prepareHeaderCell(idioma.getString("change_request.date"), fontHeader, 1F, 1F, 0F, 1F));

    tableHeader.addCell(prepareCell(project.getProjectName() + " / " + project.getAccountingCode(), fontCell,
            0F, 0F, 0F, 1F));
    tableHeader.addCell(prepareCell(preparedBy.getContact().getFullName(), fontCell, 0F, 0F, 0F, 1F));
    tableHeader.addCell(prepareCell(DateUtil.format(idioma, new Date()), fontCell, 0F, 1F, 0F, 1F));

    tableHeader.addCell(
            prepareHeaderCell(idioma.getString("change_request.customer"), fontHeader, 1F, 0F, 0F, 1F));
    tableHeader.addCell(
            prepareHeaderCell(idioma.getString("change_request.contact_name"), fontHeader, 1F, 0F, 0F, 1F));
    tableHeader.addCell(
            prepareHeaderCell(idioma.getString("change_request.customer_type"), fontHeader, 1F, 1F, 0F, 1F));

    tableHeader.addCell(prepareCell(project.getCustomer() != null ? project.getCustomer().getName() : "",
            fontCell, 0F, 0F, 0F, 1F));
    tableHeader.addCell(prepareCell((project.getCustomer() != null ? project.getCustomer().getName() : "-"),
            fontCell, 0F, 0F, 0F, 1F));

    Customertype cusType = (project.getCustomer() != null ? project.getCustomer().getCustomertype() : null);
    tableHeader.addCell(prepareCell(cusType == null ? "" : cusType.getName(), fontCell, 0F, 1F, 0F, 1F));

    tableHeader.addCell(
            prepareHeaderCell(idioma.getString("change_request.business_manager"), fontHeader, 1F, 0F, 0F, 1F));
    tableHeader.addCell(
            prepareHeaderCell(idioma.getString("change_request.project_manager"), fontHeader, 1F, 0F, 0F, 1F));
    tableHeader.addCell(
            prepareHeaderCell(idioma.getString("change_request.originator"), fontHeader, 1F, 1F, 0F, 1F));

    Employee bm = project.getEmployeeByFunctionalManager();
    Employee pm = project.getEmployeeByProjectManager();

    tableHeader.addCell(prepareCell(bm == null ? "" : bm.getContact().getFullName(), fontCell, 0F, 0F, 1F, 1F));
    tableHeader.addCell(prepareCell(pm == null ? "" : pm.getContact().getFullName(), fontCell, 0F, 0F, 1F, 1F));
    tableHeader.addCell(prepareCell(change.getOriginator(), fontCell, 0F, 1F, 1F, 1F));

    document.add(tableHeader);

    // Change Information
    document.add(new Paragraph(idioma.getString("change_information")));

    PdfPTable tableInfo = new PdfPTable(1);
    tableInfo.setWidthPercentage(100);
    tableInfo.setSpacingBefore(10);
    tableInfo.setSpacingAfter(15);

    tableInfo.addCell(prepareHeaderCell(idioma.getString("change.change_type"), fontHeader, 1F, 1F, 0F, 1F));
    tableInfo.addCell(prepareCell(change.getChangetype().getDescription(), fontCell, 0F, 1F, 0F, 1F));

    String priorityDesc = "";
    if (change.getPriority().equals('H'))
        priorityDesc = idioma.getString("change.priority.high");
    if (change.getPriority().equals('N'))
        priorityDesc = idioma.getString("change.priority.normal");
    if (change.getPriority().equals('L'))
        priorityDesc = idioma.getString("change.priority.low");

    tableInfo.addCell(prepareHeaderCell(idioma.getString("change.priority"), fontHeader, 1F, 1F, 0F, 1F));
    tableInfo.addCell(prepareCell(priorityDesc, fontCell, 0F, 1F, 0F, 1F));

    tableInfo.addCell(prepareHeaderCell(idioma.getString("change.desc"), fontHeader, 1F, 1F, 0F, 1F));
    tableInfo.addCell(prepareCell(change.getDescription(), fontCell, 0F, 1F, 0F, 1F));

    tableInfo.addCell(
            prepareHeaderCell(idioma.getString("change.recommended_solution"), fontHeader, 1F, 1F, 0F, 1F));
    tableInfo.addCell(prepareCell(change.getRecommendedSolution(), fontCell, 0F, 1F, 1F, 1F));

    PdfPTable tableSubInfo = new PdfPTable(3);
    tableSubInfo.setWidthPercentage(100);

    //TODO MIGRACION
    tableSubInfo.addCell(prepareSubCell(idioma.getString("change.wbs_node"), fontHeader));
    tableSubInfo.addCell(prepareSubCell(idioma.getString("change.estimated_effort"), fontHeader));
    tableSubInfo.addCell(prepareSubCell(idioma.getString("change.estimated_cost"), fontHeader));

    tableSubInfo.addCell(
            prepareSubCell((change.getWbsnode() != null ? change.getWbsnode().getName() : ""), fontCell));
    tableSubInfo.addCell(prepareSubCell(
            (change.getEstimatedEffort() != null ? String.valueOf(change.getEstimatedEffort()) : ""),
            fontCell));
    tableSubInfo.addCell(prepareSubCell(
            (change.getEstimatedCost() != null ? ValidateUtil.toCurrency(change.getEstimatedCost()) : ""),
            fontCell));

    PdfPCell subTable = new PdfPCell(tableSubInfo);
    subTable.setBorderWidth(1F);

    tableInfo.addCell(subTable);

    tableInfo.addCell(prepareHeaderCell(idioma.getString("change.impact_desc"), fontHeader, 1F, 1F, 0F, 1F));
    tableInfo.addCell(prepareCell(change.getImpactDescription(), fontCell, 0F, 1F, 1F, 1F));

    document.add(tableInfo);

    document.add(new Paragraph(idioma.getString("change.resolution")));

    PdfPTable tableResolution = new PdfPTable(1);
    tableResolution.setWidthPercentage(100);
    tableResolution.setSpacingBefore(10);
    tableResolution.setSpacingAfter(15);

    tableResolution
            .addCell(prepareHeaderCell(idioma.getString("change.resolution"), fontHeader, 1F, 1F, 0F, 1F));
    tableResolution.addCell(
            prepareCell((change.getResolution() != null && change.getResolution() ? idioma.getString("yes")
                    : idioma.getString("no")), fontCell, 0F, 1F, 0F, 1F));

    tableResolution
            .addCell(prepareHeaderCell(idioma.getString("change.resolution_date"), fontHeader, 1F, 1F, 0F, 1F));
    tableResolution.addCell(
            prepareCell(DateUtil.format(idioma, change.getResolutionDate()), fontCell, 0F, 1F, 0F, 1F));

    tableResolution.addCell(
            prepareHeaderCell(idioma.getString("change.resolution_reason"), fontHeader, 1F, 1F, 0F, 1F));
    tableResolution.addCell(prepareCell(change.getResolutionReason(), fontCell, 0F, 1F, 1F, 1F));

    document.add(tableResolution);

    document.close();

    try {

        PdfReader reader = new PdfReader(outputStream.toByteArray());
        PdfStamper stamper = new PdfStamper(reader, outputStream);

        int numPag = reader.getNumberOfPages();

        for (int i = 1; i <= reader.getNumberOfPages(); i++) {
            setHeaderFooter(i, numPag, headerImg, footerImg, reader, stamper, idioma);
        }

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

    file = outputStream.toByteArray();

    return file;
}

From source file:Export.ExporOnlyViagemPdf.java

private Phrase funcaoTitulo(int i) {
    String txt;//from   w  w  w.j  a  v  a 2 s  .c o m
    Font fontcabecatable = new Font(Font.FontFamily.COURIER, 8, Font.BOLD);
    switch (i) {
    case 0:
        txt = "S/N";
        break;
    case 1:
        txt = "DATA";
        break;
    case 2:
        txt = "APOLICE";
        break;
    case 3:
        txt = "DATA INICIO";
        break;
    case 4:
        txt = "DATA FIM";
        break;
    case 5:
        txt = "NO. DIAS";
        break;
    case 6:
        txt = "NOME";
        break;
    case 7:
        txt = "RECEIPT NO.";
        break;
    case 8:
        txt = "EA PREM";
        break;
    case 9:
        txt = "NICON COMISSO";
        break;
    case 10:
        txt = "5% IMPOSTO";
        break;
    case 11:
        txt = "0.60% SELO";
        break;
    //           case 12:txt="NET OUT OF TAX";break;
    default:
        txt = "TOTAL"/*"NET OUT OF TAX"*/;
        break;
    }

    Phrase rt = new Phrase(txt, fontcabecatable);
    return rt;
}

From source file:facturacion.pdf.FacturaPdf.java

@SuppressWarnings("unused")
private Paragraph getInformationFooter(String informacion) {
    Paragraph paragraph = new Paragraph();
    Chunk chunk = new Chunk();
    paragraph.setAlignment(Element.ALIGN_CENTER);
    chunk.append(informacion);//from   w  w  w  .  j a  v  a  2  s  .c  om
    chunk.setFont(new Font(Font.FontFamily.COURIER, 8, Font.NORMAL));
    paragraph.add(chunk);
    return paragraph;
}

From source file:femr.ui.controllers.PDFController.java

License:Open Source License

/**
 * Builds the page header - Title and Empty cell (for border)
 *
 * @return PdfPTable the itext table to add to the document
 *///from   w w  w .  j  a  v a  2s .  co  m
public PdfPTable createHeaderTable() {

    PdfPTable table = new PdfPTable(2);
    table.setSpacingAfter(10);
    table.setWidthPercentage(100);

    Paragraph title = new Paragraph("Medical Record", new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD));
    PdfPCell cell = new PdfPCell(title);
    cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setBorderColorBottom(BaseColor.BLACK);
    cell.setBorderWidthBottom(1);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    //Paragraph encounterId = new Paragraph("Encounter ID: " + patientEncounter.getId(), new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
    cell = new PdfPCell(table.getDefaultCell());
    cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setBorderColorBottom(BaseColor.BLACK);
    cell.setBorderWidthBottom(1);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    return table;
}

From source file:forensics_app.SharedModel.java

public static void writePDF(List<List<List>> final_result) {
    List<List> al = new ArrayList<List>();
    Font catFont = new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD);
    Font redFont = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.RED);
    Font blueFont = new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.NORMAL, BaseColor.BLUE);
    Font subFont = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD);
    Font smallBold = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD);
    String fileName = System.getProperty("user.home") + "\\Desktop\\" + System.currentTimeMillis() + ".pdf";
    Document document = null;//from  w  w  w  .  ja  v a2s.c om
    document = new Document();
    try {
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(fileName));
        document.open();
        document.add(new Phrase("\n"));
        document.add(new Paragraph("ForEye Smart Report", redFont));
        document.add(new Phrase("\n\n"));
        for (int z = 0; z < 3; z++) {
            al = final_result.get(z);
            switch (z) {
            case 0:
                if (al != null) {
                    document.add(new Phrase("\n-> History\n", blueFont));
                    document.add(new Paragraph("This user interseted in  " + al.get(0).get(0) + "  by "
                            + String.valueOf(al.get(1).get(0)) + "%", catFont));
                    document.add(new Phrase("\nthe rest of report\n", subFont));
                    for (int j = 0; j < al.get(0).size(); j++) {
                        document.add(new Phrase(
                                al.get(0).get(j) + "  by " + String.valueOf(al.get(1).get(j)) + "%"));
                        document.add(new Phrase("\n"));
                    }
                    document.add(new Phrase("\n\n"));
                }
                break;
            case 1:
                if (al != null) {
                    document.add(new Phrase("\n-> Download\n", blueFont));
                    document.add(new Paragraph("This user interseted in  " + al.get(0).get(0) + "  by "
                            + String.valueOf(al.get(1).get(0)) + "%", catFont));
                    document.add(new Phrase("\nthe rest of report\n", subFont));
                    for (int j = 0; j < al.get(0).size(); j++) {
                        document.add(new Phrase(
                                al.get(0).get(j) + "  by " + String.valueOf(al.get(1).get(j)) + "%"));
                        document.add(new Phrase("\n"));
                    }
                    document.add(new Phrase("\n\n"));
                }
                break;
            case 2:
                if (al != null) {
                    document.add(new Phrase("\n-> Bookmarks\n", blueFont));
                    document.add(new Paragraph("This user interseted in  " + al.get(0).get(0) + "  by "
                            + String.valueOf(al.get(1).get(0)) + "%", catFont));
                    document.add(new Phrase("\nthe rest of report\n", subFont));
                    for (int j = 0; j < al.get(0).size(); j++) {
                        document.add(new Phrase(
                                al.get(0).get(j) + "  by " + String.valueOf(al.get(1).get(j)) + "%"));
                        document.add(new Phrase("\n"));
                    }
                    document.add(new Phrase("\n\n"));
                }
                break;
            }
        }
        document.close();
        writer.close();
        if (Desktop.isDesktopSupported()) {
            try {
                File myFile = new File(fileName);
                Desktop.getDesktop().open(myFile);
            } catch (IOException ex) {
                // no application registered for PDFs
            }
        }
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
}

From source file:fxml.test.PDFService.java

private PdfPTable createDocumentHeader() throws IOException, BadElementException {

    //start creating header for the document......
    PdfPTable headerTable = new PdfPTable(3);
    headerTable.setHorizontalAlignment(Element.ALIGN_LEFT);
    try {//from   ww  w  . j  a va  2 s.  co  m
        headerTable.setTotalWidth(new float[] { 57.5f, 531.5f, 183f });
        headerTable.setLockedWidth(true);

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

    Image image = Image.getInstance(getClass().getClassLoader().getResource("img/sust.jpg"));
    image.scalePercent(42f);
    image.setAlignment(Element.ALIGN_LEFT);
    PdfPCell imageCell = new PdfPCell(image, false);
    imageCell.setPaddingTop(6);
    imageCell.setBorder(Rectangle.NO_BORDER);
    headerTable.addCell(imageCell);

    //start info table.....
    PdfPTable infoTable = new PdfPTable(1);
    infoTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);

    String universityText = "SHAHJALAL UNIVERSITY OF SCIENCE & TECHNOLOGY SYLHET, BANGLADESH";
    String tabulationText = "TABULATION SHEET";
    String deptText = inputs.get(0).trim();

    String s1 = inputs.get(1).trim();
    String s2 = inputs.get(2).trim();
    String semesterText = ("B.Sc (Engg.) " + s1 + " SEMESTER EXAMINATION " + s2);

    String session = inputs.get(3).trim();
    String date = inputs.get(4).trim();

    String sessionDateText = ("SESSION:" + session + " EXAMINATION HELD IN: " + date);

    infoTable.addCell(getCellForHeaderString(universityText, 0, false, 0, Element.ALIGN_CENTER, font10, true));
    infoTable.addCell(getCellForHeaderString(tabulationText, 0, false, 0, Element.ALIGN_CENTER, font10, false));
    infoTable.addCell(getCellForHeaderString(deptText, 0, false, 0, Element.ALIGN_CENTER, font10, false));
    infoTable.addCell(getCellForHeaderString(semesterText, 0, false, 0, Element.ALIGN_CENTER, font10, false));
    infoTable
            .addCell(getCellForHeaderString(sessionDateText, 0, false, 0, Element.ALIGN_CENTER, font10, false));
    //end info table.....

    PdfPCell infoCell = new PdfPCell(infoTable);
    infoCell.setBorder(Rectangle.NO_BORDER);
    headerTable.addCell(infoCell);

    PdfPCell resultPublishDateCell = new PdfPCell(
            new Paragraph("Result Published On............................",
                    new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD)));
    resultPublishDateCell.setBorder(Rectangle.NO_BORDER);
    resultPublishDateCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    resultPublishDateCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    headerTable.addCell(resultPublishDateCell);
    headerTable.setSpacingAfter(17.5f);
    // System.err.println("completed header table");
    return headerTable;
    //end creating header for the document......
}

From source file:gestionEtat.imprimerBulletin.BulletinCtrl.java

@Override
public void enregistrerBulletin() {
    if (FacesContext.getCurrentInstance().getExternalContext().getSessionMap().containsKey("user")) {

        if (eleveAnneeClasse.getId() != null) {
            classematieres.clear();//ww w .j a v a2  s . c o  m
            matieres.clear();
            notesPropres.clear();
            matiereCompses.clear();
            eleveAnneeClasse = eleveAnneeClasseFacade.find(eleveAnneeClasse.getId());
            if (sequence != null) {
                Annee an = anneeFacade.findByEtatSingle(true);
                Eleveanneeclasse eleveClasse = eleveAnneeClasseFacade.getEleveAnneeClaseByAnneClasse(
                        eleveAnneeClasse.getEleve().getIdeleve(), an.getIdannee());
                if (eleveClasse != null) {
                    List<Naturematiere> nature = natureMatiereFacade.findAll();
                    if (!nature.isEmpty()) {
                        List<Evaluation> notes = evaluationFacadeLocal.getByEleveAnneeSequence(
                                eleveAnneeClasse.getEleve().getIdeleve(), an.getIdannee(),
                                sequence.getIdsequencean());

                        /*if (!notes.isEmpty()) {*/
                        try {

                            String bulletinName = "" + eleveAnneeClasse.getEleve().getNom() + "_"
                                    + eleveAnneeClasse.getEleve().getPrenom() + "_"
                                    + sequence.getIdsequence().getNom() + ".pdf";
                            Document bulletin = new Document();

                            PdfWriter.getInstance(bulletin, new FileOutputStream(Utilitaires.path + "/"
                                    + Utilitaires.repertoireParDefautBulletin + "/" + bulletinName));

                            bulletin.setMargins(5, 5, 5, 5);
                            bulletin.addCreator("School Manager");
                            bulletin.setPageSize(PageSize.A4);

                            bulletin.open();

                            //tableau qui va contenir les notes
                            PdfPTable table = new PdfPTable(5);
                            table.setComplete(true);

                            //entete de bulletin
                            table.addCell(
                                    PrintUtils.createPdfPCell("COLLEGE POZAM Anne Scolaire " + an.getCode()
                                            + " - " + (an.getCode() + 1) + " " + an.getTheme(), 5, detail));
                            table.addCell(PrintUtils.createPdfPCell(
                                    "BULLETIN DE NOTES DE : " + sequence.getIdsequence().getNom(), 5, true));
                            table.addCell(PrintUtils
                                    .createPdfPCell("Nom : " + eleveAnneeClasse.getEleve().getNom(), 2, false));

                            PdfPCell cellLogo = new PdfPCell(new Paragraph("  "));
                            cellLogo.setRowspan(2);
                            table.addCell(cellLogo);

                            table.addCell(PrintUtils.createPdfPCell(
                                    "Matricule : " + eleveAnneeClasse.getEleve().getMatricule(), 2, false));

                            table.addCell(PrintUtils.createPdfPCell(
                                    "Prnom : " + eleveAnneeClasse.getEleve().getPrenom(), 2, false));

                            //table.addCell("kenne");
                            PdfPCell cellClasse = new PdfPCell(
                                    new Paragraph("Classe : " + eleveClasse.getIdclasse().getNom()));
                            cellClasse.setColspan(2);
                            table.addCell(cellClasse);

                            //debut de saisis de notes
                            PdfPTable entete = new PdfPTable(5);
                            table.addCell(new Paragraph("Dicipline"));
                            table.addCell(PrintUtils.createPdfPCell("Note ", true));
                            table.addCell(PrintUtils.createPdfPCell("Cofficient ", true));
                            table.addCell(PrintUtils.createPdfPCell("Total", true));
                            table.addCell(PrintUtils.createPdfPCell("Apprciation", true));

                            //partie qui contient es totaux
                            PdfPTable total = new PdfPTable(5);

                            int totalCoef = 0;
                            float totalPoint = 0;

                            classematieres = classeMatiereFacade
                                    .get(eleveAnneeClasse.getIdclasse().getIdclasse());
                            if (!classematieres.isEmpty()) {
                                for (Classematiere m : classematieres) {
                                    matieres.add(m.getIdmatiere());
                                }

                                /*for (Evaluation e : notes) {
                                 if (matieres.contains(e.getIdmatiere())) {
                                 notesPropres.add(e);
                                 matiereCompses.add(e.getIdmatiere());
                                 }
                                 }*/
                                for (int i = 0; i < nature.size(); i++) {
                                    table.addCell(
                                            PrintUtils.createPdfPCell("Matires " + nature.get(i).getLibelle(),
                                                    5, false, PrintUtils.blueFont));

                                    int totalCoefBloc = 0;
                                    int totalPointBloc = 0;

                                    for (int a = 0; a < matieres.size(); a++) {

                                        if (matiereCompses.contains(matieres.get(a))) {
                                            //if (Objects.equals(notesPropres.get(a).getIdmatiere(), nature.get(i).getIdnaturematiere())) {;
                                            //decompte des coefficient et nombre point globaux
                                            //totalCoef += notesPropres.get(a).getIdmatiere().getCoeficient();
                                            // totalPoint += notesPropres.get(a).getNote() * notesPropres.get(a).getIdmatiere().getCoeficient();

                                            //decompte des coef et point par groupe                                          
                                            //totalCoefBloc += notesPropres.get(a).getIdmatiere().getCoeficient();
                                            //totalPointBloc += notesPropres.get(a).getNote() * notesPropres.get(a).getIdmatiere().getCoeficient();
                                            //                                                    table.addCell(PrintUtils.createPdfPCell("" + notesPropres.get(a).getIdmatiere().getIdtypematiere().getLibelle(), false, new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                                            //table.addCell(PrintUtils.createPdfPCell("" + notesPropres.get(a).getNote(), true, new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                                            //table.addCell(PrintUtils.createPdfPCell("" + notesPropres.get(a).getIdmatiere().getCoeficient(), true, new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                                            //table.addCell(PrintUtils.createPdfPCell("" + (notesPropres.get(a).getNote() * notesPropres.get(a).getIdmatiere().getCoeficient()), true, new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                                            //table.addCell(PrintUtils.createPdfPCell("" + notesPropres.get(a).getObservation(), true, new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.ITALIC)));
                                            // }
                                        } else {
                                            if (Objects.equals(
                                                    matieres.get(a).getIdnaturematiere().getIdnaturematiere(),
                                                    nature.get(i).getIdnaturematiere())) {
                                                //decompte des coefficient et nombre point globaux
                                                //                                                    totalCoef += matieres.get(a).get
                                                totalPoint += 0;
                                                //decompte des coef et point par groupe                                          
                                                //                                                    totalCoefBloc += matieres.get(a).getCoeficient();
                                                totalPointBloc += 0;

                                                //                                                    table.addCell(PrintUtils.createPdfPCell("" + matieres.get(a).getIdtypematiere().getLibelle(), false, new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                                                table.addCell(PrintUtils.createPdfPCell("O", true, new Font(
                                                        Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                                                //                                                    table.addCell(PrintUtils.createPdfPCell("" + matieres.get(a).getCoeficient(), true, new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                                                table.addCell(PrintUtils.createPdfPCell("0", true, new Font(
                                                        Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                                                table.addCell(PrintUtils.createPdfPCell("Pas encore valu",
                                                        true, new Font(Font.FontFamily.TIMES_ROMAN, 10,
                                                                Font.ITALIC)));
                                            }
                                        }
                                    }

                                    //le texte Total pour chaque bloc
                                    PdfPCell cellTotalBlocText = new PdfPCell(
                                            new Paragraph("Total Matires " + nature.get(i).getLibelle() + " ",
                                                    new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL)));
                                    cellTotalBlocText.setColspan(2);
                                    table.addCell(cellTotalBlocText);

                                    table.addCell(PrintUtils.createPdfPCell("" + totalCoefBloc, true, new Font(
                                            Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL, BaseColor.RED)));

                                    table.addCell(PrintUtils.createPdfPCell("" + totalPointBloc, 2, true,
                                            new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL,
                                                    BaseColor.RED)));

                                    table.addCell(PrintUtils.createPdfPCell(
                                            "Moyenne Matires  " + nature.get(i).getLibelle(), 3, false,
                                            PrintUtils.blueFont));
                                    if (totalCoefBloc != 0) {
                                        table.addCell(PrintUtils.createPdfPCell(
                                                "" + (totalPointBloc / totalCoefBloc) + "/20", 2, true,
                                                PrintUtils.redFont));
                                    } else {
                                        table.addCell(PrintUtils.createPdfPCell("......", 2, true,
                                                PrintUtils.redFont));
                                    }
                                    table.addCell(PrintUtils.createPdfPCell("  ", 5, false));
                                }
                            } else {

                            }
                            //on ecrit totaux
                            table.addCell(PrintUtils.createPdfPCell("Totaux  ", 2, false,
                                    new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL, BaseColor.BLUE)));

                            //on met le total de coefficient
                            table.addCell(PrintUtils.createPdfPCell("" + totalCoef, true,
                                    new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL, BaseColor.RED)));

                            //on met le total de point
                            table.addCell(PrintUtils.createPdfPCell("" + totalPoint, 2, true,
                                    new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL, BaseColor.RED)));

                            table.addCell(PrintUtils.createPdfPCell(
                                    "Moyenne de la " + sequence.getIdsequence().getNom(), 3, false,
                                    new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.BLUE)));
                            if (totalCoef != 0) {
                                table.addCell(PrintUtils.createPdfPCell((totalPoint / totalCoef) + "/20", 2,
                                        true,
                                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.RED)));
                            }

                            bulletin.add(table);
                            bulletin.close();
                            JsfUtil.addSuccessMessage(
                                    "Opration russie,redirigez-vous dans le repertoire bulletin");
                        } catch (DocumentException ex) {
                            Logger.getLogger(BulletinCtrl.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (FileNotFoundException ex) {
                            Logger.getLogger(BulletinCtrl.class.getName()).log(Level.SEVERE, null, ex);
                        }
                        /*} else {
                         JsfUtil.addErrorMessage("L'lve selectionn n a aucune note  la squence slectionne");
                         }*/
                    } else {
                        JsfUtil.addErrorMessage("Aucune nature de matiere parametre");
                    }
                } else {
                    JsfUtil.addErrorMessage("l'eleve n a pas de classe");
                }
            } else {
                JsfUtil.addErrorMessage("veuillez selectionner une squence !");
            }
        } else {
            JsfUtil.addErrorMessage("Veuillez selectionner un lve");
        }
    } else {
        String sc = FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath();
        try {
            FacesContext.getCurrentInstance().getExternalContext().redirect(sc + "/login.html");
        } catch (IOException ex) {
            Logger.getLogger(BulletinCtrl.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:gestionEtat.imprimerBulletin.BulletinCtrl.java

@Override
public void imprimerListeClasse() {
    if (FacesContext.getCurrentInstance().getExternalContext().getSessionMap().containsKey("user")) {
        if (classe != null) {
            Annee an = anneeFacade.findByEtatSingle(true);
            if (an != null) {
                List<Eleveanneeclasse> elevs = eleveAnneeClasseFacade.findByAnneeClasse(an.getIdannee(),
                        classe.getIdclasse());
                if (!elevs.isEmpty()) {

                    try {
                        String listeName = "liste_des_eleve_" + classe.getNom() + ".pdf";
                        Document liste = new Document();
                        liste.setMargins(2, 2, 2, 2);
                        PdfWriter.getInstance(liste, new FileOutputStream(Utilitaires.path + "/"
                                + Utilitaires.repertoireParDefautClasse + "/" + listeName));
                        liste.open();/*from  w  w  w .j av  a 2s  .c o  m*/

                        PdfPTable table = new PdfPTable(4);
                        table.setComplete(true);

                        table.addCell(PrintUtils.createPdfPCell("Liste des lves de la " + classe.getNom()
                                + " Anne Scolaire : " + an.getCode() + " - " + (an.getCode() + 1), 4, true));

                        table.addCell(PrintUtils.createPdfPCell("NOM", true,
                                new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL)));
                        table.addCell(PrintUtils.createPdfPCell("PRENOM", true,
                                new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL)));
                        table.addCell(PrintUtils.createPdfPCell("MATRICULE", true,
                                new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL)));
                        table.addCell(PrintUtils.createPdfPCell("DATE DE NAISSANCE", true,
                                new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL)));

                        //debut d'ecriture des lignes;
                        for (int i = 0; i < elevs.size(); i++) {
                            table.addCell(PrintUtils.createPdfPCell("" + elevs.get(i).getEleve().getNom(), true,
                                    new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL)));
                            table.addCell(PrintUtils.createPdfPCell("" + elevs.get(i).getEleve().getPrenom(),
                                    true, new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL)));
                            table.addCell(PrintUtils.createPdfPCell("" + elevs.get(i).getEleve().getMatricule(),
                                    true, new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL)));
                            table.addCell(PrintUtils.createPdfPCell(
                                    "" + elevs.get(i).getEleve().getDatenaissance().getDay() + "-"
                                            + elevs.get(i).getEleve().getDatenaissance().getMonth() + "-"
                                            + elevs.get(i).getEleve().getDatenaissance().getYear(),
                                    true, new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL)));
                        }

                        liste.add(table);

                        liste.close();

                        JsfUtil.addSuccessMessage("Impression russie !");
                    } catch (FileNotFoundException | DocumentException ex) {
                        Logger.getLogger(BulletinCtrl.class.getName()).log(Level.SEVERE, null, ex);
                    }
                } else {
                    JsfUtil.addErrorMessage("La classe selectionne n'a aucune !");
                }
            } else {
                JsfUtil.addFatalErrorMessage("L'anne en cours n'est pas parametre");
            }
        } else {
            JsfUtil.addErrorMessage("Veuillez selectionner une classe !");
        }
    } else {
        String sc = FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath();
        try {
            FacesContext.getCurrentInstance().getExternalContext().redirect(sc + "/login.html");
        } catch (IOException ex) {
            Logger.getLogger(BulletinCtrl.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:gestionEtat.imprimerListeEleve.ListeEleveCtrl.java

@Override
public void imprimerListeClasse() {
    if (FacesContext.getCurrentInstance().getExternalContext().getSessionMap().containsKey("user")) {
        if (classe != null) {
            Annee an = anneeFacade.findByEtatSingle(true);
            if (an != null) {
                List<Eleveanneeclasse> elevs = eleveAnneeClasseFacade.findByAnneeClasse(an.getIdannee(),
                        classe.getIdclasse());
                if (!elevs.isEmpty()) {

                    try {
                        String listeName = "liste_des_eleve_" + classe.getNom() + ".pdf";
                        Document liste = new Document();
                        liste.setMargins(2, 2, 2, 2);
                        PdfWriter.getInstance(liste, new FileOutputStream(Utilitaires.path + "/"
                                + Utilitaires.repertoireParDefautClasse + "/" + listeName));
                        liste.open();/*from w  ww  . ja va  2 s .  c o  m*/

                        PdfPTable table = new PdfPTable(4);
                        table.setComplete(true);

                        table.addCell(PrintUtils.createPdfPCell("Liste des lves de la " + classe.getNom()
                                + " Anne Scolaire : " + an.getCode() + " - " + (an.getCode() + 1), 4, true));

                        table.addCell(PrintUtils.createPdfPCell("NOM", true,
                                new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL)));
                        table.addCell(PrintUtils.createPdfPCell("PRENOM", true,
                                new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL)));
                        table.addCell(PrintUtils.createPdfPCell("MATRICULE", true,
                                new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL)));
                        table.addCell(PrintUtils.createPdfPCell("DATE DE NAISSANCE", true,
                                new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL)));

                        //debut d'ecriture des lignes;
                        for (int i = 0; i < elevs.size(); i++) {
                            table.addCell(PrintUtils.createPdfPCell("" + elevs.get(i).getEleve().getNom(), true,
                                    new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL)));
                            table.addCell(PrintUtils.createPdfPCell("" + elevs.get(i).getEleve().getPrenom(),
                                    true, new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL)));
                            table.addCell(PrintUtils.createPdfPCell("" + elevs.get(i).getEleve().getMatricule(),
                                    true, new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL)));
                            table.addCell(PrintUtils.createPdfPCell(
                                    "" + elevs.get(i).getEleve().getDatenaissance().getDay() + "-"
                                            + elevs.get(i).getEleve().getDatenaissance().getMonth() + "-"
                                            + elevs.get(i).getEleve().getDatenaissance().getYear(),
                                    true, new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL)));
                        }

                        liste.add(table);

                        liste.close();

                        JsfUtil.addSuccessMessage("Impression russie !");
                    } catch (FileNotFoundException | DocumentException ex) {
                        Logger.getLogger(ListeEleveCtrl.class.getName()).log(Level.SEVERE, null, ex);
                    }
                } else {
                    JsfUtil.addErrorMessage("La classe selectionne n'a aucune !");
                }
            } else {
                JsfUtil.addFatalErrorMessage("L'anne en cours n'est pas parametre");
            }
        } else {
            JsfUtil.addErrorMessage("Veuillez selectionner une classe !");
        }
    } else {
        String sc = FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath();
        try {
            FacesContext.getCurrentInstance().getExternalContext().redirect(sc + "/login.html");
        } catch (IOException ex) {
            Logger.getLogger(ListeEleveCtrl.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}