Example usage for com.lowagie.text Paragraph setIndentationLeft

List of usage examples for com.lowagie.text Paragraph setIndentationLeft

Introduction

In this page you can find the example usage for com.lowagie.text Paragraph setIndentationLeft.

Prototype

public void setIndentationLeft(float indentation) 

Source Link

Document

Sets the indentation of this paragraph on the left side.

Usage

From source file:fr.univlorraine.mondossierweb.controllers.InscriptionController.java

License:Apache License

/**
 * /*from   w w  w  . ja  v a  2s .  com*/
 * @param document pdf
 */
public void creerPdfCertificatScolarite(final Document document, Etudiant etudiant, Inscription inscription) {

    //configuration des fonts
    Font normal = FontFactory.getFont(FontFactory.HELVETICA, 10, Font.NORMAL);
    Font normalBig = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD);
    Font header = FontFactory.getFont(FontFactory.HELVETICA, 14, Font.BOLD);

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

    document.open();
    try {

        Signataire signataire = multipleApogeeService
                .getSignataire(configController.getCertScolCodeSignataire());

        // Ajout Bordeaux1
        if (configController.isCertScolUtiliseLogo()) {
            //ajout image test
            if (configController.getLogoUniversitePdf() != null
                    && !configController.getLogoUniversitePdf().equals("")) {
                Image imageLogo = Image.getInstance(configController.getLogoUniversitePdf());
                float scaleRatio = 40 / imageLogo.getHeight();
                float newWidth = scaleRatio * imageLogo.getWidth();
                imageLogo.scaleAbsolute(newWidth, 40);
                imageLogo.setAbsolutePosition(100, 750);
                document.add(imageLogo);
            } else if (configController.getCertScolHeaderUniv() != null
                    && !configController.getCertScolHeaderUniv().equals("")) {
                Image imageHeader = Image.getInstance(configController.getCertScolHeaderUniv());
                float scaleHeader = 600 / imageHeader.getWidth();
                float newHeigthHeader = scaleHeader * imageHeader.getHeight();
                imageHeader.scaleAbsolute(600, newHeigthHeader);
                imageHeader.setAbsolutePosition(0, 765);
                document.add(imageHeader);
            }

            if (configController.getCertScolFooter() != null
                    && !configController.getCertScolFooter().equals("")) {
                Image imageFooter = Image.getInstance(configController.getCertScolFooter());
                float scaleFooter = 600 / imageFooter.getWidth();
                float newHeigthFooter = scaleFooter * imageFooter.getHeight();
                imageFooter.scaleAbsolute(600, newHeigthFooter);
                imageFooter.setAbsolutePosition(0, 0);
                document.add(imageFooter);
            }
        }

        Paragraph pTitre = new Paragraph("\n\n" + applicationContext
                .getMessage("pdf.certificat.title", null, Locale.getDefault()).toUpperCase(), header);
        pTitre.setAlignment(Element.ALIGN_CENTER);
        document.add(pTitre);

        Paragraph pCertifie = new Paragraph("\n\n\n\n" + signataire.getQua_sig() + " "
                + applicationContext.getMessage("pdf.certificat.certifie", null, Locale.getDefault()) + "\n\n",
                normal);
        pCertifie.setAlignment(Element.ALIGN_LEFT);
        document.add(pCertifie);

        if (etudiant.getNom() != null) {
            String civ = multipleApogeeService.getCodCivFromCodInd(etudiant.getCod_ind());
            String civCertif = "";
            if (civ != null) {
                if (civ.equals("1")) {
                    civCertif = applicationContext.getMessage("pdf.certificat.civ1", null, Locale.getDefault());
                } else if (civ.equals("2")) {
                    civCertif = applicationContext.getMessage("pdf.certificat.civ2", null, Locale.getDefault());
                }
            }
            Paragraph pNom = new Paragraph(civCertif + " " + etudiant.getNom(), normalBig);
            pNom.setIndentationLeft(15);
            document.add(pNom);
        }
        if (etudiant.getCod_nne() != null) {
            Paragraph pNNE = new Paragraph(
                    "\n" + applicationContext.getMessage("pdf.certificat.id", null, Locale.getDefault()) + " : "
                            + etudiant.getCod_nne().toLowerCase(),
                    normal);
            pNNE.setAlignment(Element.ALIGN_LEFT);
            document.add(pNNE);
        }
        if (etudiant.getCod_etu() != null) {
            Paragraph p01 = new Paragraph(
                    applicationContext.getMessage("pdf.certificat.numetudiant", null, Locale.getDefault())
                            + " : " + etudiant.getCod_etu(),
                    normal);
            p01.setAlignment(Element.ALIGN_LEFT);
            document.add(p01);
        }
        if (etudiant.getDatenaissance() != null) {
            Paragraph pDateNaissance = new Paragraph(
                    applicationContext.getMessage("pdf.certificat.naissance1", null, Locale.getDefault()) + " "
                            + etudiant.getDatenaissance(),
                    normal);
            pDateNaissance.setAlignment(Element.ALIGN_LEFT);
            document.add(pDateNaissance);
        }
        if ((etudiant.getLieunaissance() != null) && (etudiant.getDepartementnaissance() != null)) {
            Paragraph pLieuNaissance = new Paragraph(
                    applicationContext.getMessage("pdf.certificat.naissance2", null, Locale.getDefault()) + " "
                            + etudiant.getLieunaissance() + " (" + etudiant.getDepartementnaissance() + ")",
                    normal);
            pLieuNaissance.setAlignment(Element.ALIGN_LEFT);
            document.add(pLieuNaissance);
        }

        String anneeEnCours = etudiantController.getAnneeUnivEnCoursToDisplay(MainUI.getCurrent());
        String inscritCertif = "";
        if (inscription.getCod_anu().equals(anneeEnCours)) {
            inscritCertif = applicationContext.getMessage("pdf.certificat.inscrit", null, Locale.getDefault());
        } else {
            inscritCertif = applicationContext.getMessage("pdf.certificat.ete.inscrit", null,
                    Locale.getDefault());
        }
        Paragraph pEstInscrit = new Paragraph("\n" + inscritCertif + " " + inscription.getCod_anu() + "\n ",
                normal);
        pEstInscrit.setAlignment(Element.ALIGN_LEFT);
        document.add(pEstInscrit);

        float[] widths = { 1.5f, 7.5f };
        PdfPTable table = new PdfPTable(widths);
        table.setWidthPercentage(100f);
        table.addCell(makeCell(applicationContext.getMessage("pdf.diplome", null, Locale.getDefault()) + " :",
                normal));
        table.addCell(makeCell(inscription.getLib_dip(), normal));
        table.addCell(
                makeCell(applicationContext.getMessage("pdf.year", null, Locale.getDefault()) + " :", normal));
        table.addCell(makeCell(inscription.getLib_etp(), normal));
        table.addCell(makeCell(
                applicationContext.getMessage("pdf.composante", null, Locale.getDefault()) + " :", normal));
        table.addCell(makeCell(inscription.getLib_comp(), normal));
        document.add(table);

        document.add(new Paragraph(" "));

        float[] widthsSignataire = { 2f, 1.3f };
        PdfPTable tableSignataire = new PdfPTable(widthsSignataire);
        tableSignataire.setWidthPercentage(100f);
        tableSignataire.addCell(makeCellSignataire("", normal));
        tableSignataire
                .addCell(makeCellSignataire(
                        applicationContext.getMessage("pdf.certificat.fait1", null, Locale.getDefault()) + " "
                                + configController.getCertScolLieuEdition() + applicationContext.getMessage(
                                        "pdf.certificat.fait2", null, Locale.getDefault())
                                + " " + date,
                        normal));
        tableSignataire.addCell(makeCellSignataire("", normal));
        tableSignataire.addCell(makeCellSignataire(signataire.getNom_sig(), normal));
        //ajout signature
        if (signataire.getImg_sig_std() != null && signataire.getImg_sig_std().length > 0) { //MODIF 09/10/2012
            tableSignataire.addCell(makeCellSignataire("", normal));
            LOG.debug(signataire.getImg_sig_std().toString());
            Image imageSignature = Image.getInstance(signataire.getImg_sig_std());

            float scaleRatio = 100 / imageSignature.getHeight();
            float newWidth = scaleRatio * imageSignature.getWidth();
            imageSignature.scaleAbsolute(newWidth, 100);
            imageSignature.setAbsolutePosition(350, 225);
            document.add(imageSignature);

        }

        document.add(tableSignataire);

        // Ajout tampon
        if (configController.getCertScolTampon() != null && !configController.getCertScolTampon().equals("")) {
            Image imageTampon = Image.getInstance(configController.getCertScolTampon());
            float scaleTampon = 100 / imageTampon.getWidth();
            float newHeigthTampon = scaleTampon * imageTampon.getHeight();
            imageTampon.scaleAbsolute(100, newHeigthTampon);
            imageTampon.setAbsolutePosition(415, 215);
            document.add(imageTampon);
        }

    } catch (BadElementException e) {
        LOG.error("Erreur  la gnration du certificat : BadElementException ", e);
    } catch (MalformedURLException e) {
        LOG.error("Erreur  la gnration du certificat : MalformedURLException ", e);
    } catch (IOException e) {
        LOG.error("Erreur  la gnration du certificat : IOException ", e);
    } catch (DocumentException e) {
        LOG.error("Erreur  la gnration du certificat : DocumentException ", e);
    }
    // step 6: fermeture du document.
    document.close();

}

From source file:fr.univlorraine.mondossierweb.controllers.ListeInscritsController.java

License:Apache License

/**
 * /*from   w ww.  j a v a2 s  .co  m*/
 * @param document pdf
 */
public void creerPdfTrombinoscope(final Document document, List<Inscrit> listeInscrits,
        List<String> listecodind, String libelle, String annee) {

    //configuration des fonts
    Font normal = FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.NORMAL);
    Font normalbig = FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD);
    Font legerita = FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.ITALIC);
    Font leger = FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.NORMAL);
    Font headerbig = FontFactory.getFont(FontFactory.TIMES_ROMAN, 16, Font.BOLD);
    Font header = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.BOLD);

    //pieds de pages:
    String part = "";
    Date d = new Date();
    DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
    String date = dateFormat.format(d);
    //alignement des libells du pied de page:
    String partie1 = libelle + " " + annee;
    String partie2 = applicationContext.getMessage("pdf.edition.date", null, Locale.getDefault()) + " : "
            + date;
    if (partie1.length() < ECARTEMENT_PIED_PAGE_PDF) {
        int diff = ECARTEMENT_PIED_PAGE_PDF - partie1.length();
        for (int i = 0; i < diff; i++) {
            partie1 = partie1 + " ";

        }
    }
    if (partie2.length() < ECARTEMENT_PIED_PAGE_PDF) {
        int diff = ECARTEMENT_PIED_PAGE_PDF - partie2.length();
        for (int i = 0; i < diff; i++) {
            partie2 = " " + partie2;
        }
    }

    //cration du pied de page:
    Phrase phra = new Phrase(partie1 + "-" + part + " Page", legerita);
    Phrase phra2 = new Phrase("- " + partie2, legerita);
    HeaderFooter hf = new HeaderFooter(phra, phra2);
    hf.setAlignment(HeaderFooter.ALIGN_CENTER);
    document.setFooter(hf);

    //ouverte du document.
    document.open();

    try {

        //ajout image test
        if (configController.getLogoUniversitePdf() != null
                && !configController.getLogoUniversitePdf().equals("")) {
            Image image1 = Image.getInstance(configController.getLogoUniversitePdf());
            float scaleRatio = 40 / image1.getHeight();
            float newWidth = scaleRatio * image1.getWidth();
            image1.scaleAbsolute(newWidth, 40);
            image1.setAbsolutePosition(800 - newWidth, 528);
            document.add(image1);
        }

        Paragraph p = new Paragraph(applicationContext
                .getMessage("pdf.trombinoscope.title", null, Locale.getDefault()).toUpperCase(), headerbig);
        p.setIndentationLeft(15);
        document.add(p);

        Paragraph p3 = new Paragraph(
                applicationContext.getMessage("pdf.promotion", null, Locale.getDefault()) + " : " + libelle,
                normal);
        p3.setIndentationLeft(15);
        document.add(p3);

        Paragraph p2 = new Paragraph(
                applicationContext.getMessage("pdf.year", null, Locale.getDefault()) + " : " + annee, normal);
        p2.setIndentationLeft(15);
        document.add(p2);

        Paragraph p4 = new Paragraph(applicationContext.getMessage("pdf.nbinscrits", null, Locale.getDefault())
                + " : " + listecodind.size(), normal);
        p4.setIndentationLeft(15);
        document.add(p4);

        Paragraph p03 = new Paragraph(
                applicationContext.getMessage("pdf.edition.date", null, Locale.getDefault()) + " : " + date
                        + "\n\n",
                normal);
        p03.setIndentationLeft(15);
        document.add(p03);

        PdfPTable table = new PdfPTable(NB_INSCRITS_LIGNE_TROMBI_PDF);
        table.setWidthPercentage(100f);

        int compteur = 0;
        Rectangle border = new Rectangle(0f, 0f);
        border.setBorderColorLeft(Color.WHITE);
        border.setBorderColorBottom(Color.WHITE);
        border.setBorderColorRight(Color.WHITE);
        border.setBorderColorTop(Color.WHITE);

        String tabNom[] = new String[NB_INSCRITS_LIGNE_TROMBI_PDF];
        String tabNum[] = new String[NB_INSCRITS_LIGNE_TROMBI_PDF];
        //insertion de listeInscrits dans listeInscritstrombi si le trombinoscope n'est pas decoup
        /*   if (listeInscritsTrombi == null || listeInscritsTrombi.size() == 0) {
           ArrayList<Inscrit> listeInscritsbis = (ArrayList<Inscrit>) listeInscrits.clone();
           listeInscritsTrombi.add(listeInscritsbis);
        }*/
        //nombre d'etudiants insrer a la suite dans le pdf:
        int nbEtudiantInsere = 0;
        for (Inscrit inscrit : listeInscrits) {
            if (listecodind.contains(inscrit.getCod_ind())) {
                nbEtudiantInsere++;
                //on en a insr le plus possible d'un coup (pour eviter un timeout du server 
                //de photos sur les premieres photos 
                //au moment de l'insertion dans le pdf : document.add() ):
                //on insere la table dans le pdf et on recommence une nouvelle table
                if (nbEtudiantInsere > (NB_INSCRITS_LIGNE_TROMBI_PDF
                        * NB_LIGNE_INSEREE_TROMBI_PDF_A_LA_SUITE)) {
                    document.add(table);
                    document.newPage();
                    table = new PdfPTable(NB_INSCRITS_LIGNE_TROMBI_PDF);
                    table.setWidthPercentage(100f);
                    tabNom = new String[NB_INSCRITS_LIGNE_TROMBI_PDF];
                    tabNum = new String[NB_INSCRITS_LIGNE_TROMBI_PDF];
                    nbEtudiantInsere = 1;
                    compteur = 0;
                }

                tabNom[compteur] = "" + inscrit.getPrenom() + " \n" + inscrit.getNom() + "\n";
                tabNum[compteur] = "" + inscrit.getCod_etu();

                compteur++;

                //String foto = photo.getUrlPhotoTrombinoscopePdf(inscrit.getCod_ind(), inscrit.getCod_etu());
                String foto = GenericUI.getCurrent().getPhotoProvider().getUrlPhotoTrombinoscopePdf(
                        inscrit.getCod_ind(), inscrit.getCod_etu(), userController.isEnseignant(),
                        userController.getCurrentUserName());
                Image photo = Image.getInstance(foto);
                photo.scaleAbsolute(85, 107);

                PdfPCell cell = new PdfPCell(photo);
                cell.cloneNonPositionParameters(border);
                table.addCell(cell);

                if (compteur == NB_INSCRITS_LIGNE_TROMBI_PDF) {
                    for (int i = 0; i < NB_INSCRITS_LIGNE_TROMBI_PDF; i++) {
                        Phrase ph = new Phrase(tabNom[i], normalbig);
                        Phrase ph2 = new Phrase(tabNum[i], leger);
                        Paragraph pinscrit = new Paragraph();
                        pinscrit.add(ph);
                        pinscrit.add(ph2);
                        PdfPCell celltext = new PdfPCell(pinscrit);
                        celltext.cloneNonPositionParameters(border);
                        table.addCell(celltext);
                    }
                    compteur = 0;
                }

            }

        }
        if (compteur > 0) {
            for (int i = compteur; i < NB_INSCRITS_LIGNE_TROMBI_PDF; i++) {
                PdfPCell cell = new PdfPCell();
                cell.cloneNonPositionParameters(border);
                table.addCell(cell);
            }

            for (int i = 0; i < compteur; i++) {
                Phrase ph = new Phrase(tabNom[i], normalbig);
                Phrase ph2 = new Phrase(tabNum[i], leger);
                Paragraph pinscrit = new Paragraph();
                pinscrit.add(ph);
                pinscrit.add(ph2);
                PdfPCell celltext = new PdfPCell(pinscrit);
                celltext.cloneNonPositionParameters(border);
                table.addCell(celltext);
            }

            for (int i = compteur; i < NB_INSCRITS_LIGNE_TROMBI_PDF; i++) {
                PdfPCell cell = new PdfPCell();
                cell.cloneNonPositionParameters(border);
                table.addCell(cell);
            }

        }

        document.add(table);

    } catch (BadElementException e) {
        LOG.error("Erreur  la gnration du certificat : BadElementException ", e);
    } catch (MalformedURLException e) {
        LOG.error("Erreur  la gnration du certificat : MalformedURLException ", e);
    } catch (IOException e) {
        LOG.error("Erreur  la gnration du certificat : IOException ", e);
    } catch (DocumentException e) {
        LOG.error("Erreur  la gnration du certificat : DocumentException ", e);
    }

    // step 6: fermeture du document.
    document.close();

}

From source file:fr.univlorraine.mondossierweb.controllers.NoteController.java

License:Apache License

/**
 * // w  w  w .  jav a  2  s. c o  m
 * @param document pdf
 */
public void creerPdfResume(final Document document, Etudiant etudiant) {

    //configuration des fonts
    Font normal = FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.NORMAL);
    Font normalbig = FontFactory.getFont(FontFactory.TIMES_ROMAN, 11, Font.BOLD);
    Font legerita = FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.ITALIC);
    Font headerbig = FontFactory.getFont(FontFactory.TIMES_ROMAN, 16, Font.BOLD);
    Font header = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.BOLD);

    //pieds de pages:
    Date d = new Date();
    DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
    String date = dateFormat.format(d);
    //alignement des libell du pied de page:
    String partie1 = applicationContext.getMessage("pdf.notes.title", null, Locale.getDefault());
    String partie2 = applicationContext.getMessage("pdf.edition.date", null, Locale.getDefault()) + " : "
            + date;
    if (partie1.length() < ECARTEMENT_PIED_PAGE_PDF) {
        int diff = ECARTEMENT_PIED_PAGE_PDF - partie1.length();
        for (int i = 0; i < diff; i++) {
            partie1 = partie1 + " ";

        }
    }
    if (partie2.length() < ECARTEMENT_PIED_PAGE_PDF) {
        int diff = ECARTEMENT_PIED_PAGE_PDF - partie2.length();
        for (int i = 0; i < diff; i++) {
            partie2 = " " + partie2;
        }
    }

    //creation du pied de page:
    Phrase phra = new Phrase(
            partie1 + " -" + applicationContext.getMessage("pdf.page", null, Locale.getDefault()), legerita);
    Phrase phra2 = new Phrase("- " + partie2, legerita);
    HeaderFooter hf = new HeaderFooter(phra, phra2);
    hf.setAlignment(HeaderFooter.ALIGN_CENTER);
    document.setFooter(hf);

    //ouverte du document.
    document.open();
    try {
        //ajout image test
        if (configController.getLogoUniversitePdf() != null
                && !configController.getLogoUniversitePdf().equals("")) {
            Image image1 = Image.getInstance(configController.getLogoUniversitePdf());
            float scaleRatio = 40 / image1.getHeight();
            float newWidth = scaleRatio * image1.getWidth();
            image1.scaleAbsolute(newWidth, 40);
            image1.setAbsolutePosition(800 - newWidth, 528);
            document.add(image1);
        }

        boolean affMentionEtudiant = configController.isAffMentionEtudiant();

        //nouveau paragraphe
        Paragraph p = new Paragraph(applicationContext.getMessage("pdf.notes.title", null, Locale.getDefault())
                .toUpperCase(Locale.getDefault()) + "\n\n", headerbig);
        p.setIndentationLeft(15);
        document.add(p);

        if (etudiant.getNom() != null) {
            Paragraph p0 = new Paragraph(etudiant.getNom(), normal);
            p0.setIndentationLeft(15);
            document.add(p0);
        }
        if (etudiant.getCod_etu() != null) {
            Paragraph p01 = new Paragraph(applicationContext.getMessage("pdf.folder", null, Locale.getDefault())
                    + " : " + etudiant.getCod_etu(), normal);
            p01.setIndentationLeft(15);
            document.add(p01);
        }
        if (etudiant.getCod_nne() != null) {
            Paragraph p02 = new Paragraph(applicationContext.getMessage("pdf.nne", null, Locale.getDefault())
                    + " : " + etudiant.getCod_nne(), normal);
            p02.setIndentationLeft(15);
            document.add(p02);
        }
        if (etudiant.getEmail() != null) {
            Paragraph p03 = new Paragraph(applicationContext.getMessage("pdf.mail", null, Locale.getDefault())
                    + " : " + etudiant.getEmail(), normal);
            p03.setIndentationLeft(15);
            document.add(p03);
        }

        Paragraph p03 = new Paragraph(
                applicationContext.getMessage("pdf.edition.date", null, Locale.getDefault()) + " : " + date,
                normal);
        p03.setIndentationLeft(15);
        document.add(p03);
        document.add(new Paragraph("\n"));

        //Partie DIPLOMES
        PdfPTable table = new PdfPTable(1);
        table.setWidthPercentage(98);
        PdfPCell cell = new PdfPCell(
                new Paragraph(applicationContext.getMessage("pdf.diplomes", null, Locale.getDefault())
                        .toUpperCase(Locale.getDefault()) + " ", header));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setBackgroundColor(new Color(153, 153, 255));
        table.addCell(cell);

        PdfPTable table2;

        //if(!config.isAffRangEtudiant()){
        if (!etudiant.isAfficherRang()) {
            table2 = new PdfPTable(4);
        } else {
            table2 = new PdfPTable(5);
        }

        table2.setWidthPercentage(98);

        int tailleColonneLib = 110;
        if (affMentionEtudiant)
            tailleColonneLib = 90;

        //if(!config.isAffRangEtudiant()){
        if (!etudiant.isAfficherRang()) {
            int[] tabWidth = { 26, 35, tailleColonneLib, 70 };
            table2.setWidths(tabWidth);
        } else {
            int[] tabWidth = { 26, 35, tailleColonneLib - 5, 70, 15 };
            table2.setWidths(tabWidth);
        }

        Paragraph p1 = new Paragraph(applicationContext.getMessage("pdf.year", null, Locale.getDefault()),
                normalbig);
        Paragraph p2 = new Paragraph(applicationContext.getMessage("pdf.code.vers", null, Locale.getDefault()),
                normalbig);
        Paragraph p3 = new Paragraph(applicationContext.getMessage("pdf.diplome", null, Locale.getDefault()),
                normalbig);

        PdfPCell ct1 = new PdfPCell(p1);
        PdfPCell ct2 = new PdfPCell(p2);
        PdfPCell ct3 = new PdfPCell(p3);

        ct1.setBorder(Rectangle.BOTTOM);
        ct1.setBorderColorBottom(Color.black);
        ct2.setBorder(Rectangle.BOTTOM);
        ct2.setBorderColorBottom(Color.black);
        ct3.setBorder(Rectangle.BOTTOM);
        ct3.setBorderColorBottom(Color.black);

        table2.addCell(ct1);
        table2.addCell(ct2);
        table2.addCell(ct3);

        PdfPTable table21;
        if (!affMentionEtudiant) {
            table21 = new PdfPTable(3);
            int[] tabWidth21 = { 25, 20, 25 };
            table21.setWidths(tabWidth21);
        } else {
            table21 = new PdfPTable(4);
            int[] tabWidth21 = { 25, 20, 25, 20 };
            table21.setWidths(tabWidth21);
        }

        PdfPCell ct4 = new PdfPCell(new Paragraph(
                applicationContext.getMessage("pdf.session", null, Locale.getDefault()), normalbig));
        PdfPCell ct5 = new PdfPCell(
                new Paragraph(applicationContext.getMessage("pdf.note", null, Locale.getDefault()), normalbig));
        PdfPCell ct6 = new PdfPCell(new Paragraph(
                applicationContext.getMessage("pdf.resultat", null, Locale.getDefault()), normalbig));
        PdfPCell ctmention = new PdfPCell(new Paragraph(
                applicationContext.getMessage("pdf.mention", null, Locale.getDefault()), normalbig));

        ct4.setBorder(Rectangle.BOTTOM);
        ct4.setBorderColorBottom(Color.black);
        ct5.setBorder(Rectangle.BOTTOM);
        ct5.setBorderColorBottom(Color.black);
        ct6.setBorder(Rectangle.BOTTOM);
        ct6.setBorderColorBottom(Color.black);
        ctmention.setBorder(Rectangle.BOTTOM);
        ctmention.setBorderColorBottom(Color.black);

        table21.addCell(ct4);
        table21.addCell(ct5);
        table21.addCell(ct6);
        if (affMentionEtudiant) {
            table21.addCell(ctmention);
        }

        PdfPCell ct7 = new PdfPCell(table21);
        ct7.setBorder(Rectangle.BOTTOM);
        table2.addCell(ct7);

        PdfPCell ctrang = new PdfPCell(
                new Paragraph(applicationContext.getMessage("pdf.rank", null, Locale.getDefault()), normalbig));
        ctrang.setBorder(Rectangle.BOTTOM);
        ctrang.setBorderColorBottom(Color.black);

        //if(config.isAffRangEtudiant()){
        if (etudiant.isAfficherRang()) {
            table2.addCell(ctrang);
        }

        for (int i = 0; i < etudiant.getDiplomes().size(); i++) {
            Paragraph pa = new Paragraph(etudiant.getDiplomes().get(i).getAnnee(), normal);
            PdfPCell celltext = new PdfPCell(pa);
            celltext.setBorder(Rectangle.NO_BORDER);

            Paragraph pa2 = new Paragraph(etudiant.getDiplomes().get(i).getCod_dip() + "/"
                    + etudiant.getDiplomes().get(i).getCod_vrs_vdi(), normal);
            PdfPCell celltext2 = new PdfPCell(pa2);
            celltext2.setBorder(Rectangle.NO_BORDER);

            Paragraph pa3 = new Paragraph(etudiant.getDiplomes().get(i).getLib_web_vdi(), normal);
            PdfPCell celltext3 = new PdfPCell(pa3);
            celltext3.setBorder(Rectangle.NO_BORDER);

            Paragraph parang = new Paragraph(etudiant.getDiplomes().get(i).getRang(), normal);
            PdfPCell cellrang = new PdfPCell(parang);
            cellrang.setBorder(Rectangle.NO_BORDER);

            PdfPCell cellvide = new PdfPCell();
            cellvide.setBorder(Rectangle.NO_BORDER);

            table2.addCell(celltext);
            table2.addCell(celltext2);
            table2.addCell(celltext3);

            PdfPTable table3;
            if (!affMentionEtudiant) {
                table3 = new PdfPTable(3);
                int[] tabWidth2 = { 25, 20, 25 };
                table3.setWidths(tabWidth2);
            } else {
                table3 = new PdfPTable(4);
                int[] tabWidth2 = { 25, 20, 25, 8 };
                table3.setWidths(tabWidth2);
            }

            int j = 0;
            List<Resultat> lres = etudiant.getDiplomes().get(i).getResultats();
            while (j < lres.size()) {

                Paragraph pa5 = new Paragraph(lres.get(j).getSession(), normal);
                PdfPCell celltext5 = new PdfPCell(pa5);
                celltext5.setBorder(Rectangle.NO_BORDER);
                table3.addCell(celltext5);

                if (lres.get(j).getNote() != null) {
                    Paragraph pa6 = new Paragraph(lres.get(j).getNote().toString(), normal);
                    PdfPCell celltext6 = new PdfPCell(pa6);
                    celltext6.setBorder(Rectangle.NO_BORDER);
                    table3.addCell(celltext6);
                } else {
                    Paragraph pa6 = new Paragraph("", normal);
                    PdfPCell celltext6 = new PdfPCell(pa6);
                    celltext6.setBorder(Rectangle.NO_BORDER);
                    table3.addCell(celltext6);
                }

                Paragraph pa7 = new Paragraph(lres.get(j).getAdmission(), normal);
                PdfPCell celltext7 = new PdfPCell(pa7);
                celltext7.setBorder(Rectangle.NO_BORDER);
                table3.addCell(celltext7);

                if (affMentionEtudiant) {
                    Paragraph pa8 = new Paragraph(lres.get(j).getCodMention(), normal);
                    PdfPCell celltext8 = new PdfPCell(pa8);
                    celltext8.setBorder(Rectangle.NO_BORDER);
                    table3.addCell(celltext8);
                }

                j++;
            }

            PdfPCell celltext4 = new PdfPCell(table3);
            celltext4.setBorder(Rectangle.NO_BORDER);
            table2.addCell(celltext4);

            //if(config.isAffRangEtudiant()){
            if (etudiant.getDiplomes().get(i).isAfficherRang()) {
                table2.addCell(cellrang);
            } else {
                //On insere une cellule vide si on affiche pas ce rang, alors que la colonne rang fait partie de la table
                if (etudiant.isAfficherRang()) {
                    table2.addCell(cellvide);
                }
            }

        }

        document.add(table);
        document.add(table2);
        document.add(new Paragraph("\n"));

        //Partie ETAPES
        PdfPTable tabletape = new PdfPTable(1);
        tabletape.setWidthPercentage(98);
        PdfPCell celletape = new PdfPCell(new Paragraph(applicationContext
                .getMessage("pdf.etapes", null, Locale.getDefault()).toUpperCase(Locale.getDefault()), header));
        celletape.setBorder(Rectangle.NO_BORDER);
        celletape.setBackgroundColor(new Color(153, 153, 255));
        tabletape.addCell(celletape);

        PdfPTable tabletape2;

        //if(!config.isAffRangEtudiant()){
        if (!etudiant.isAfficherRang()) {
            tabletape2 = new PdfPTable(4);
            tabletape2.setWidthPercentage(98);
            int[] tabWidthetape = { 26, 35, tailleColonneLib, 70 };
            tabletape2.setWidths(tabWidthetape);
        } else {
            tabletape2 = new PdfPTable(5);
            tabletape2.setWidthPercentage(98);
            int[] tabWidthetape = { 26, 35, tailleColonneLib - 5, 70, 15 };
            tabletape2.setWidths(tabWidthetape);
        }

        PdfPCell ct3etape = new PdfPCell(new Paragraph(
                applicationContext.getMessage("pdf.etape", null, Locale.getDefault()), normalbig));
        ct3etape.setBorder(Rectangle.BOTTOM);
        ct3etape.setBorderColorBottom(Color.black);

        tabletape2.addCell(ct1);
        tabletape2.addCell(ct2);
        tabletape2.addCell(ct3etape);

        tabletape2.addCell(ct7);

        //if(!config.isAffRangEtudiant()){
        if (etudiant.isAfficherRang()) {
            tabletape2.addCell(ctrang);
        }

        for (int i = 0; i < etudiant.getEtapes().size(); i++) {
            Paragraph pa = new Paragraph(etudiant.getEtapes().get(i).getAnnee(), normal);
            PdfPCell celltext = new PdfPCell(pa);
            celltext.setBorder(Rectangle.NO_BORDER);
            tabletape2.addCell(celltext);

            Paragraph pa2 = new Paragraph(
                    etudiant.getEtapes().get(i).getCode() + "/" + etudiant.getEtapes().get(i).getVersion(),
                    normal);
            PdfPCell celltext2 = new PdfPCell(pa2);
            celltext2.setBorder(Rectangle.NO_BORDER);
            tabletape2.addCell(celltext2);

            Paragraph pa3 = new Paragraph(etudiant.getEtapes().get(i).getLibelle(), normal);
            PdfPCell celltext3 = new PdfPCell(pa3);
            celltext3.setBorder(Rectangle.NO_BORDER);
            tabletape2.addCell(celltext3);

            Paragraph parEtapeRang = new Paragraph(etudiant.getEtapes().get(i).getRang(), normal);
            PdfPCell cellEtapeRang = new PdfPCell(parEtapeRang);
            cellEtapeRang.setBorder(Rectangle.NO_BORDER);

            PdfPCell cellvide = new PdfPCell();
            cellvide.setBorder(Rectangle.NO_BORDER);

            PdfPTable table3;

            if (!affMentionEtudiant) {
                table3 = new PdfPTable(3);
                int[] tabWidth2 = { 25, 20, 25 };
                table3.setWidths(tabWidth2);
            } else {
                table3 = new PdfPTable(4);
                int[] tabWidth2 = { 25, 20, 25, 8 };
                table3.setWidths(tabWidth2);
            }

            int j = 0;
            List<Resultat> lres = etudiant.getEtapes().get(i).getResultats();
            while (j < lres.size()) {

                Paragraph pa5 = new Paragraph(lres.get(j).getSession(), normal);
                PdfPCell celltext5 = new PdfPCell(pa5);
                celltext5.setBorder(Rectangle.NO_BORDER);
                table3.addCell(celltext5);

                if (lres.get(j).getNote() != null) {
                    Paragraph pa6 = new Paragraph(lres.get(j).getNote().toString(), normal);
                    PdfPCell celltext6 = new PdfPCell(pa6);
                    celltext6.setBorder(Rectangle.NO_BORDER);
                    table3.addCell(celltext6);
                } else {
                    Paragraph pa6 = new Paragraph("", normal);
                    PdfPCell celltext6 = new PdfPCell(pa6);
                    celltext6.setBorder(Rectangle.NO_BORDER);
                    table3.addCell(celltext6);
                }

                Paragraph pa7 = new Paragraph(lres.get(j).getAdmission(), normal);
                PdfPCell celltext7 = new PdfPCell(pa7);
                celltext7.setBorder(Rectangle.NO_BORDER);
                table3.addCell(celltext7);

                if (affMentionEtudiant) {
                    Paragraph pa8 = new Paragraph(lres.get(j).getCodMention(), normal);
                    PdfPCell celltext8 = new PdfPCell(pa8);
                    celltext8.setBorder(Rectangle.NO_BORDER);
                    table3.addCell(celltext8);
                }

                j++;
            }
            PdfPCell celltext4 = new PdfPCell(table3);
            celltext4.setBorder(Rectangle.NO_BORDER);
            tabletape2.addCell(celltext4);

            //if(config.isAffRangEtudiant()){
            if (etudiant.getEtapes().get(i).isAfficherRang()) {
                tabletape2.addCell(cellEtapeRang);
            } else {
                if (etudiant.isAfficherRang()) {
                    tabletape2.addCell(cellvide);
                }
            }

        }

        document.add(tabletape);
        document.add(tabletape2);
        document.add(new Paragraph("\n"));

        //Partie Informations
        if (etudiant.isSignificationResultatsUtilisee()) {
            PdfPTable tablequestions = new PdfPTable(1);
            tablequestions.setWidthPercentage(98);
            PdfPCell cellquestions = new PdfPCell(new Paragraph(
                    applicationContext.getMessage("pdf.questions", null, Locale.getDefault()) + " ", header));
            cellquestions.setBorder(Rectangle.NO_BORDER);
            cellquestions.setBackgroundColor(new Color(153, 153, 255));
            tablequestions.addCell(cellquestions);

            String grilleSignficationResultats = "";
            Set<String> ss = etudiant.getSignificationResultats().keySet();
            for (String k : ss) {
                if (k != null && !k.equals("") && !k.equals(" ")) {
                    grilleSignficationResultats = grilleSignficationResultats + k + " : "
                            + etudiant.getSignificationResultats().get(k);
                    grilleSignficationResultats = grilleSignficationResultats + "   ";
                }
            }

            PdfPTable tablequestions2 = new PdfPTable(1);
            tablequestions2.setWidthPercentage(98);
            PdfPCell cellquestions2 = new PdfPCell(new Paragraph(
                    applicationContext.getMessage("pdf.code.resultat.signification", null, Locale.getDefault())
                            + " : \n" + grilleSignficationResultats,
                    normal));
            cellquestions2.setBorder(Rectangle.NO_BORDER);
            tablequestions2.addCell(cellquestions2);

            document.add(tablequestions);
            document.add(tablequestions2);
        }

    } catch (BadElementException e) {
        LOG.error("Erreur  la gnration du rsum des notes : BadElementException ", e);
    } catch (MalformedURLException e) {
        LOG.error("Erreur  la gnration du rsum des notes : MalformedURLException ", e);
    } catch (IOException e) {
        LOG.error("Erreur  la gnration du rsum des notes : IOException ", e);
    } catch (DocumentException e) {
        LOG.error("Erreur  la gnration du rsum des notes : DocumentException ", e);
    }
    // step 6: fermeture du document.
    document.close();

}

From source file:fr.univlorraine.mondossierweb.controllers.NoteController.java

License:Apache License

/**
 * //from w  w  w.  ja v a  2s.c om
 * @param document pdf
 */
public void creerPdfDetail(final Document document, Etudiant etudiant, Etape etape) {

    //configuration des fonts
    Font normal = FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.NORMAL);
    Font normalbig = FontFactory.getFont(FontFactory.TIMES_ROMAN, 11, Font.BOLD);
    Font legerita = FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.ITALIC);
    Font headerbig = FontFactory.getFont(FontFactory.TIMES_ROMAN, 16, Font.BOLD);
    Font header = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.BOLD);

    //pieds de pages:
    Date d = new Date();
    DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
    String date = dateFormat.format(d);
    //alignement des libells du pied de page:
    String partie1 = applicationContext.getMessage("pdf.notes.detail", null, Locale.getDefault());
    String partie2 = applicationContext.getMessage("pdf.edition.date", null, Locale.getDefault()) + " : "
            + date;
    if (partie1.length() < ECARTEMENT_PIED_PAGE_PDF) {
        int diff = ECARTEMENT_PIED_PAGE_PDF - partie1.length();
        for (int i = 0; i < diff; i++) {
            partie1 = partie1 + " ";

        }
    }
    if (partie2.length() < ECARTEMENT_PIED_PAGE_PDF) {
        int diff = ECARTEMENT_PIED_PAGE_PDF - partie2.length();
        for (int i = 0; i < diff; i++) {
            partie2 = " " + partie2;
        }
    }

    //creation du pied de page:
    Phrase phra = new Phrase(
            partie1 + " -" + applicationContext.getMessage("pdf.page", null, Locale.getDefault()), legerita);
    Phrase phra2 = new Phrase("- " + partie2, legerita);
    HeaderFooter hf = new HeaderFooter(phra, phra2);
    hf.setAlignment(HeaderFooter.ALIGN_CENTER);
    document.setFooter(hf);
    document.setFooter(hf);

    //ouverte du document.
    document.open();
    try {
        //ajout image test
        if (configController.getLogoUniversitePdf() != null
                && !configController.getLogoUniversitePdf().equals("")) {
            Image image1 = Image.getInstance(configController.getLogoUniversitePdf());
            float scaleRatio = 40 / image1.getHeight();
            float newWidth = scaleRatio * image1.getWidth();
            image1.scaleAbsolute(newWidth, 40);
            image1.setAbsolutePosition(800 - newWidth, 528);
            document.add(image1);
        }

        //nouveau paragraphe
        Paragraph p = new Paragraph(applicationContext.getMessage("pdf.notes.title", null, Locale.getDefault())
                .toUpperCase(Locale.getDefault()) + "\n\n", headerbig);
        p.setIndentationLeft(15);
        document.add(p);

        if (etudiant.getNom() != null) {
            Paragraph p0 = new Paragraph(etudiant.getNom(), normal);
            p0.setIndentationLeft(15);
            document.add(p0);
        }
        if (etudiant.getCod_etu() != null) {
            Paragraph p01 = new Paragraph(applicationContext.getMessage("pdf.folder", null, Locale.getDefault())
                    + " : " + etudiant.getCod_etu(), normal);
            p01.setIndentationLeft(15);
            document.add(p01);
        }
        if (etudiant.getCod_nne() != null) {
            Paragraph p02 = new Paragraph(applicationContext.getMessage("pdf.nne", null, Locale.getDefault())
                    + " : " + etudiant.getCod_nne(), normal);
            p02.setIndentationLeft(15);
            document.add(p02);
        }
        if (etudiant.getEmail() != null) {
            Paragraph p03 = new Paragraph(applicationContext.getMessage("pdf.mail", null, Locale.getDefault())
                    + " : " + etudiant.getEmail(), normal);
            p03.setIndentationLeft(15);
            document.add(p03);
        }

        Paragraph p03 = new Paragraph(
                applicationContext.getMessage("pdf.edition.date", null, Locale.getDefault()) + " : " + date,
                normal);
        p03.setIndentationLeft(15);
        document.add(p03);
        document.add(new Paragraph("\n"));

        //Partie des notes
        PdfPTable table = new PdfPTable(1);
        table.setWidthPercentage(98);
        //PdfPCell cell = new PdfPCell(new Paragraph(applicationContext.getMessage("pdf.elements.epreuves", null, Locale.getDefault()).toUpperCase(Locale.getDefault()) + " - "+applicationContext.getMessage("pdf.annee.universitaire", null, Locale.getDefault()) + " : " + etape.getAnnee(), header));
        PdfPCell cell = new PdfPCell(new Paragraph(etape.getLibelle() + " - "
                + applicationContext.getMessage("pdf.annee.universitaire", null, Locale.getDefault()) + " : "
                + etape.getAnnee(), header));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setBackgroundColor(new Color(153, 153, 255));
        table.addCell(cell);

        PdfPTable table2;

        boolean afficherRangElpEpr = etudiantController.isAfficherRangElpEpr();
        boolean affRangEtudiant = configController.isAffRangEtudiant();
        boolean affECTSEtudiant = configController.isAffECTSEtudiant();

        if ((!affRangEtudiant && !afficherRangElpEpr) && !affECTSEtudiant) {
            //NI isAffRangEtudiant  NI isAffECTSEtudiant
            table2 = new PdfPTable(6);
            table2.setWidthPercentage(98);
            int[] tabWidth = { 35, 110, 25, 25, 25, 25 };
            table2.setWidths(tabWidth);
        } else {
            if (((affRangEtudiant || afficherRangElpEpr) && !affECTSEtudiant)
                    || ((!affRangEtudiant && !afficherRangElpEpr) && affECTSEtudiant)) {
                //isAffRangEtudiant  OU isAffECTSEtudiant
                table2 = new PdfPTable(7);
                table2.setWidthPercentage(98);
                int[] tabWidth = { 33, 110, 22, 22, 22, 22, 15 };
                table2.setWidths(tabWidth);
            } else {
                //isAffRangEtudiant  ET isAffECTSEtudiant
                table2 = new PdfPTable(8);
                table2.setWidthPercentage(98);
                int[] tabWidth = { 33, 110, 22, 22, 22, 22, 15, 15 };
                table2.setWidths(tabWidth);
            }
        }

        //Paragraph p1 = new Paragraph(applicationContext.getMessage("pdf.year", null, Locale.getDefault()),normalbig);
        Paragraph p2 = new Paragraph(applicationContext.getMessage("pdf.code", null, Locale.getDefault()),
                normalbig);
        Paragraph p3 = new Paragraph(applicationContext.getMessage("pdf.label", null, Locale.getDefault()),
                normalbig);
        Paragraph parRang = new Paragraph(applicationContext.getMessage("pdf.rank", null, Locale.getDefault()),
                normalbig);
        Paragraph parEcts = new Paragraph(applicationContext.getMessage("pdf.ects", null, Locale.getDefault()),
                normalbig);

        PdfPCell ct4 = new PdfPCell(new Paragraph(
                applicationContext.getMessage("pdf.session", null, Locale.getDefault()) + " 1", normalbig));
        PdfPCell ct5 = new PdfPCell(new Paragraph(
                applicationContext.getMessage("pdf.resultat", null, Locale.getDefault()), normalbig));
        PdfPCell ct6 = new PdfPCell(new Paragraph(
                applicationContext.getMessage("pdf.session", null, Locale.getDefault()) + " 2", normalbig));
        PdfPCell ct7 = new PdfPCell(new Paragraph(
                applicationContext.getMessage("pdf.resultat", null, Locale.getDefault()), normalbig));

        //PdfPCell ct1 = new PdfPCell(p1);
        PdfPCell ct2 = new PdfPCell(p2);
        PdfPCell ct3 = new PdfPCell(p3);
        PdfPCell cellRang = new PdfPCell(parRang);
        PdfPCell cellEcts = new PdfPCell(parEcts);

        //ct1.setBorder(Rectangle.BOTTOM); ct1.setBorderColorBottom(Color.black);
        ct2.setBorder(Rectangle.BOTTOM);
        ct2.setBorderColorBottom(Color.black);
        ct3.setBorder(Rectangle.BOTTOM);
        ct3.setBorderColorBottom(Color.black);
        ct4.setBorder(Rectangle.BOTTOM);
        ct4.setBorderColorBottom(Color.black);
        ct5.setBorder(Rectangle.BOTTOM);
        ct5.setBorderColorBottom(Color.black);
        ct6.setBorder(Rectangle.BOTTOM);
        ct6.setBorderColorBottom(Color.black);
        ct7.setBorder(Rectangle.BOTTOM);
        ct7.setBorderColorBottom(Color.black);
        cellRang.setBorder(Rectangle.BOTTOM);
        cellRang.setBorderColorBottom(Color.black);
        cellEcts.setBorder(Rectangle.BOTTOM);
        cellEcts.setBorderColorBottom(Color.black);

        //table2.addCell(ct1);
        table2.addCell(ct2);
        table2.addCell(ct3);
        table2.addCell(ct4);
        table2.addCell(ct5);
        table2.addCell(ct6);
        table2.addCell(ct7);
        if ((affRangEtudiant || afficherRangElpEpr)) {
            table2.addCell(cellRang);
        }
        if (affRangEtudiant) {
            table2.addCell(cellEcts);
        }

        for (int i = 0; i < etudiant.getElementsPedagogiques().size(); i++) {
            /*String annee = etudiant.getElementsPedagogiques().get(i).getAnnee().replaceAll(applicationContext.getMessage("pdf.replace.ficm", null, Locale.getDefault()), "");
            Paragraph pa = new Paragraph(annee, normal);
            PdfPCell celltext = new PdfPCell(pa);
            celltext.setBorder(Rectangle.NO_BORDER);
            table2.addCell(celltext);*/

            Paragraph pa2 = new Paragraph(etudiant.getElementsPedagogiques().get(i).getCode(), normal);
            PdfPCell celltext2 = new PdfPCell(pa2);
            celltext2.setBorder(Rectangle.NO_BORDER);
            table2.addCell(celltext2);

            String indentation = "";
            for (int j = 0; j < etudiant.getElementsPedagogiques().get(i).getLevel(); j++) {
                indentation = indentation + "     ";
            }
            Paragraph pa3 = new Paragraph(indentation + etudiant.getElementsPedagogiques().get(i).getLibelle(),
                    normal);
            PdfPCell celltext3 = new PdfPCell(pa3);
            celltext3.setBorder(Rectangle.NO_BORDER);
            table2.addCell(celltext3);

            Paragraph pa5 = new Paragraph(getNote1(etudiant.getElementsPedagogiques().get(i)), normal);
            PdfPCell celltext5 = new PdfPCell(pa5);
            celltext5.setBorder(Rectangle.NO_BORDER);
            table2.addCell(celltext5);

            Paragraph pa6 = new Paragraph(etudiant.getElementsPedagogiques().get(i).getRes1(), normal);
            PdfPCell celltext6 = new PdfPCell(pa6);
            celltext6.setBorder(Rectangle.NO_BORDER);
            table2.addCell(celltext6);

            Paragraph pa7 = new Paragraph(getNote2(etudiant.getElementsPedagogiques().get(i)), normal);
            PdfPCell celltext7 = new PdfPCell(pa7);
            celltext7.setBorder(Rectangle.NO_BORDER);
            table2.addCell(celltext7);

            Paragraph pa8 = new Paragraph(etudiant.getElementsPedagogiques().get(i).getRes2(), normal);
            PdfPCell celltext8 = new PdfPCell(pa8);
            celltext8.setBorder(Rectangle.NO_BORDER);
            table2.addCell(celltext8);

            if ((affRangEtudiant || afficherRangElpEpr)) {
                Paragraph parRang2 = new Paragraph(etudiant.getElementsPedagogiques().get(i).getRang(), normal);
                PdfPCell cellRang2 = new PdfPCell(parRang2);
                cellRang2.setBorder(Rectangle.NO_BORDER);
                table2.addCell(cellRang2);
            }

            if (affECTSEtudiant) {
                Paragraph parEcts2 = new Paragraph(etudiant.getElementsPedagogiques().get(i).getEcts(), normal);
                PdfPCell cellEcts2 = new PdfPCell(parEcts2);
                cellEcts2.setBorder(Rectangle.NO_BORDER);
                table2.addCell(cellEcts2);
            }

        }

        document.add(table);
        document.add(table2);
        document.add(new Paragraph("\n"));

        //Partie QUESTIONS
        if (etudiant.isSignificationResultatsUtilisee()) {
            PdfPTable tablequestions = new PdfPTable(1);
            tablequestions.setWidthPercentage(98);
            PdfPCell cellquestions = new PdfPCell(
                    new Paragraph(applicationContext.getMessage("pdf.questions", null, Locale.getDefault())
                            .toUpperCase(Locale.getDefault()) + " ", header));
            cellquestions.setBorder(Rectangle.NO_BORDER);
            cellquestions.setBackgroundColor(new Color(153, 153, 255));
            tablequestions.addCell(cellquestions);

            PdfPTable tablequestions2 = new PdfPTable(1);
            tablequestions2.setWidthPercentage(98);

            String grilleSignficationResultats = "";
            Set<String> ss = etudiant.getSignificationResultats().keySet();
            for (String k : ss) {
                if (k != null && !k.equals("") && !k.equals(" ")) {
                    grilleSignficationResultats = grilleSignficationResultats + k + " : "
                            + etudiant.getSignificationResultats().get(k);
                    grilleSignficationResultats = grilleSignficationResultats + "   ";
                }
            }

            PdfPCell cellquestions2 = new PdfPCell(new Paragraph(
                    applicationContext.getMessage("pdf.code.resultat.signification", null, Locale.getDefault())
                            + " : \n" + grilleSignficationResultats,
                    normal));
            cellquestions2.setBorder(Rectangle.NO_BORDER);
            tablequestions2.addCell(cellquestions2);

            document.add(tablequestions);
            document.add(tablequestions2);

        }

    } catch (BadElementException e) {
        LOG.error("Erreur  la gnration du detail des notes : BadElementException ", e);
    } catch (MalformedURLException e) {
        LOG.error("Erreur  la gnration du detail des notes : MalformedURLException ", e);
    } catch (IOException e) {
        LOG.error("Erreur  la gnration du detail des notes : IOException ", e);
    } catch (DocumentException e) {
        LOG.error("Erreur  la gnration du detail des notes : DocumentException ", e);
    }
    // step 6: fermeture du document.
    document.close();

}

From source file:ispyb.client.mx.results.ExportAutoProcAction.java

License:Open Source License

private void setAutoProcInfo(Document document) throws Exception {
    // header//from  w w w  .j a  va2 s .  c  o  m
    Table headerTable = new Table(1);
    headerTable.getDefaultCell().setBorderWidth(0);
    headerTable.setBorderWidth(0);
    headerTable.setCellsFitPage(true);
    headerTable.setAlignment(Element.ALIGN_LEFT);
    headerTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
    headerTable.getDefaultCell().setBackgroundColor(PdfRtfExporter.LIGHT_YELLOW_COLOR);
    headerTable.getDefaultCell().setLeading(3);
    headerTable.setWidth(100); // percentage
    headerTable
            .addCell(new Paragraph("Crystal data and data-collection statistics", PdfRtfExporter.FONT_DOC_11));
    headerTable.addCell(new Paragraph("Values in parentheses are for the highest resolution shell.",
            PdfRtfExporter.FONT_DOC_11));
    document.add(headerTable);
    document.add(new Paragraph(" ", PdfRtfExporter.VERY_SMALL_FONT));
    // auto proc table
    Table autoProcTable = new Table(2);
    autoProcTable.getDefaultCell().setBorderWidth(0);
    autoProcTable.setBorderWidth(0);
    autoProcTable.setCellsFitPage(true);
    autoProcTable.setAlignment(Element.ALIGN_LEFT);
    autoProcTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
    // autoProcTable.getDefaultCell().setLeading(3);
    autoProcTable.setPadding(2);
    autoProcTable.setWidth(100); // percentage
    // data
    String spaceGroup = autoProc == null ? "" : autoProc.getSpaceGroup();
    String unitCell_a = autoProc == null ? "" : autoProc.getRefinedCellA().toString();
    String unitCell_b = autoProc == null ? "" : autoProc.getRefinedCellB().toString();
    String unitCell_c = autoProc == null ? "" : autoProc.getRefinedCellC().toString();
    String unitCell_alpha = autoProc == null ? "" : autoProc.getRefinedCellAlpha().toString();
    String unitCell_beta = autoProc == null ? "" : autoProc.getRefinedCellBeta().toString();
    String unitCell_gamma = autoProc == null ? "" : autoProc.getRefinedCellGamma().toString();
    String resolutionRange = "";
    String nTotalObservations = "";
    String nTotalUniqueReflections = "";
    String completeness = "";
    String multiplicity = "";
    String isigma = "";
    String rmerge = "";
    if (autoProcStatisticsOverall != null) {
        resolutionRange = autoProcStatisticsOverall.getResolutionLimitLow() + " - "
                + autoProcStatisticsOverall.getResolutionLimitHigh();
        nTotalObservations = "" + autoProcStatisticsOverall.getnTotalObservations();
        nTotalUniqueReflections = "" + (autoProcStatisticsOverall.getnTotalUniqueObservations() == null ? ""
                : autoProcStatisticsOverall.getnTotalUniqueObservations());
        completeness = "" + autoProcStatisticsOverall.getCompleteness();
        multiplicity = "" + autoProcStatisticsOverall.getMultiplicity();
        isigma = "" + autoProcStatisticsOverall.getMeanIoverSigI();
        rmerge = ""
                + (autoProcStatisticsOverall.getRmerge() == null ? "" : autoProcStatisticsOverall.getRmerge());
    }
    if (autoProcStatisticsOuter != null) {
        resolutionRange += " (" + autoProcStatisticsOuter.getResolutionLimitLow() + " - "
                + autoProcStatisticsOuter.getResolutionLimitHigh() + ")";
        nTotalObservations += " (" + autoProcStatisticsOuter.getnTotalObservations() + ")";
        nTotalUniqueReflections += autoProcStatisticsOuter.getnTotalUniqueObservations() == null ? ""
                : (" (" + autoProcStatisticsOuter.getnTotalUniqueObservations() + ")");
        completeness += " (" + autoProcStatisticsOuter.getCompleteness() + ")";
        multiplicity += " (" + autoProcStatisticsOuter.getMultiplicity() + ")";
        isigma += " (" + autoProcStatisticsOuter.getMeanIoverSigI() + ")";
        rmerge += " ("
                + (autoProcStatisticsOuter.getRmerge() == null ? "" : autoProcStatisticsOuter.getRmerge())
                + ")";
    }
    // space group
    autoProcTable.addCell(new Paragraph("Space Group", PdfRtfExporter.FONT_DOC_11));
    autoProcTable.addCell(new Paragraph(spaceGroup, PdfRtfExporter.FONT_DOC_11));
    // unit cell parameters
    autoProcTable.addCell(
            new Paragraph("Unit-cell parameters (" + Constants.ANGSTROM + ")", PdfRtfExporter.FONT_DOC_11));
    autoProcTable.addCell(new Paragraph("", PdfRtfExporter.FONT_DOC_11));
    Paragraph pa = new Paragraph("\t a", PdfRtfExporter.FONT_DOC_11);
    pa.setAlignment(Element.ALIGN_JUSTIFIED);
    pa.setIndentationLeft(PdfRtfExporter.INDENTATION_LEFT);
    autoProcTable.addCell(pa);
    autoProcTable.addCell(new Paragraph(unitCell_a, PdfRtfExporter.FONT_DOC_11));
    Paragraph pb = new Paragraph("\t b", PdfRtfExporter.FONT_DOC_11);
    pb.setAlignment(Element.ALIGN_JUSTIFIED);
    pb.setIndentationLeft(PdfRtfExporter.INDENTATION_LEFT);
    autoProcTable.addCell(pb);
    autoProcTable.addCell(new Paragraph(unitCell_b, PdfRtfExporter.FONT_DOC_11));
    Paragraph pc = new Paragraph("\t c", PdfRtfExporter.FONT_DOC_11);
    pc.setAlignment(Element.ALIGN_JUSTIFIED);
    pc.setIndentationLeft(PdfRtfExporter.INDENTATION_LEFT);
    autoProcTable.addCell(pc);
    autoProcTable.addCell(new Paragraph(unitCell_c, PdfRtfExporter.FONT_DOC_11));
    // Issue 1733: cell angles info added
    Paragraph palpha = new Paragraph("\t alpha", PdfRtfExporter.FONT_DOC_11);
    palpha.setAlignment(Element.ALIGN_JUSTIFIED);
    palpha.setIndentationLeft(PdfRtfExporter.INDENTATION_LEFT);
    autoProcTable.addCell(palpha);
    autoProcTable.addCell(new Paragraph(unitCell_alpha, PdfRtfExporter.FONT_DOC_11));
    Paragraph pbeta = new Paragraph("\t beta", PdfRtfExporter.FONT_DOC_11);
    pbeta.setAlignment(Element.ALIGN_JUSTIFIED);
    pbeta.setIndentationLeft(PdfRtfExporter.INDENTATION_LEFT);
    autoProcTable.addCell(pbeta);
    autoProcTable.addCell(new Paragraph(unitCell_beta, PdfRtfExporter.FONT_DOC_11));
    Paragraph pgamma = new Paragraph("\t gamma", PdfRtfExporter.FONT_DOC_11);
    pgamma.setAlignment(Element.ALIGN_JUSTIFIED);
    pgamma.setIndentationLeft(PdfRtfExporter.INDENTATION_LEFT);
    autoProcTable.addCell(pgamma);
    autoProcTable.addCell(new Paragraph(unitCell_gamma, PdfRtfExporter.FONT_DOC_11));
    // resolution range
    autoProcTable.addCell(
            new Paragraph("Resolution range (" + Constants.ANGSTROM + ")", PdfRtfExporter.FONT_DOC_11));
    autoProcTable.addCell(new Paragraph(resolutionRange, PdfRtfExporter.FONT_DOC_11));
    // Observed reflections
    autoProcTable.addCell(new Paragraph("Observed reflections", PdfRtfExporter.FONT_DOC_11));
    autoProcTable.addCell(new Paragraph(nTotalObservations, PdfRtfExporter.FONT_DOC_11));
    // No. of unique reflections
    autoProcTable.addCell(new Paragraph("No. of unique reflections", PdfRtfExporter.FONT_DOC_11));
    autoProcTable.addCell(new Paragraph(nTotalUniqueReflections, PdfRtfExporter.FONT_DOC_11));
    // Completeness
    autoProcTable.addCell(new Paragraph("Completeness (%)", PdfRtfExporter.FONT_DOC_11));
    autoProcTable.addCell(new Paragraph(completeness, PdfRtfExporter.FONT_DOC_11));
    // multiplicity
    autoProcTable.addCell(new Paragraph("Multiplicity", PdfRtfExporter.FONT_DOC_11));
    autoProcTable.addCell(new Paragraph(multiplicity, PdfRtfExporter.FONT_DOC_11));
    new Phrase();
    // I/(I)
    Phrase p = Phrase.getInstance("<I/" + (char) 963 + "(I)>");
    p.setFont(PdfRtfExporter.FONT_DOC_11);
    autoProcTable.addCell(p);
    autoProcTable.addCell(new Paragraph(isigma, PdfRtfExporter.FONT_DOC_11));
    // Rmerge
    Chunk c1 = new Chunk("R", PdfRtfExporter.FONT_DOC_11);
    Chunk c2 = new Chunk("merge", PdfRtfExporter.FONT_DOC_EXPONENT);
    c2.setTextRise(PdfRtfExporter.TEXT_RISE_SUB);
    Chunk c3 = new Chunk("(%)", PdfRtfExporter.FONT_DOC_11);
    Chunk c4 = new Chunk("#", PdfRtfExporter.FONT_DOC_EXPONENT_BLUE);
    c4.setTextRise(PdfRtfExporter.TEXT_RISE_EXP);
    Paragraph rMergeParagraph = new Paragraph();
    rMergeParagraph.add(c1);
    rMergeParagraph.add(c2);
    rMergeParagraph.add(c3);
    rMergeParagraph.add(c4);
    autoProcTable.addCell(rMergeParagraph);
    autoProcTable.addCell(new Paragraph(rmerge, PdfRtfExporter.FONT_DOC_11));
    document.add(autoProcTable);
    document.add(new Paragraph(" ", PdfRtfExporter.FONT_DOC_11));
    // nota bene info
    Paragraph nbParagraph = new Paragraph();
    nbParagraph.add(c4);
    nbParagraph.add(c1);
    nbParagraph.add(c2);
    Chunk cesp = new Chunk(" ", PdfRtfExporter.FONT_DOC_11);
    Chunk c5 = new Chunk(" = ", PdfRtfExporter.FONT_DOC_11);
    nbParagraph.add(c5);
    Phrase pSigma = Phrase.getInstance("" + (char) 931);
    pSigma.setFont(PdfRtfExporter.FONT_DOC_11);
    nbParagraph.add(pSigma);
    Chunk chkl = new Chunk("hkl", PdfRtfExporter.FONT_DOC_EXPONENT);
    chkl.setTextRise(PdfRtfExporter.TEXT_RISE_SUB);
    nbParagraph.add(chkl);
    nbParagraph.add(cesp);
    nbParagraph.add(pSigma);
    Chunk ci = new Chunk("i", PdfRtfExporter.FONT_DOC_EXPONENT);
    ci.setTextRise(PdfRtfExporter.TEXT_RISE_SUB);
    nbParagraph.add(ci);
    Chunk c8 = new Chunk(" |I", PdfRtfExporter.FONT_DOC_11);
    nbParagraph.add(c8);
    nbParagraph.add(ci);
    Chunk c9 = new Chunk("(hkl) - (I(hkl))| / ", PdfRtfExporter.FONT_DOC_11);
    nbParagraph.add(c9);
    nbParagraph.add(pSigma);
    nbParagraph.add(chkl);
    nbParagraph.add(cesp);
    nbParagraph.add(pSigma);
    nbParagraph.add(ci);
    nbParagraph.add(cesp);
    Chunk c10 = new Chunk("I", PdfRtfExporter.FONT_DOC_11);
    nbParagraph.add(c10);
    nbParagraph.add(ci);
    Chunk c11 = new Chunk("(hkl), where ", PdfRtfExporter.FONT_DOC_11);
    nbParagraph.add(c11);
    Chunk c12 = new Chunk("I", PdfRtfExporter.FONT_DOC_11_ITALIC);
    nbParagraph.add(c12);
    Chunk cii = new Chunk("i", PdfRtfExporter.FONT_DOC_EXPONENT_ITALIC);
    cii.setTextRise(PdfRtfExporter.TEXT_RISE_SUB);
    nbParagraph.add(cii);
    Chunk c13 = new Chunk("(hkl)", PdfRtfExporter.FONT_DOC_11_ITALIC);
    nbParagraph.add(c13);
    Chunk c14 = new Chunk(" is the ", PdfRtfExporter.FONT_DOC_11);
    nbParagraph.add(c14);
    Chunk c15 = new Chunk("i", PdfRtfExporter.FONT_DOC_11_ITALIC);
    nbParagraph.add(c15);
    Chunk c16 = new Chunk("th observation of reflection ", PdfRtfExporter.FONT_DOC_11);
    nbParagraph.add(c16);
    Chunk chklI = new Chunk("hkl", PdfRtfExporter.FONT_DOC_11_ITALIC);
    nbParagraph.add(chklI);
    Chunk c17 = new Chunk(" and ", PdfRtfExporter.FONT_DOC_11);
    nbParagraph.add(c17);
    Chunk c18 = new Chunk("<I(hkl)> ", PdfRtfExporter.FONT_DOC_11_ITALIC);
    nbParagraph.add(c18);
    Chunk c19 = new Chunk(" is the weighted average intensity for all observations of reflection ",
            PdfRtfExporter.FONT_DOC_11);
    nbParagraph.add(c19);
    nbParagraph.add(chklI);
    Chunk c20 = new Chunk(".", PdfRtfExporter.FONT_DOC_11);
    nbParagraph.add(c20);
    document.add(nbParagraph);
    document.add(new Paragraph(" ", PdfRtfExporter.FONT_DOC_11));
}

From source file:net.bull.javamelody.internal.web.pdf.PdfCounterRequestContextReport.java

License:Apache License

private void writeRequest(CounterRequestContext context, PdfPCell cell, int margin)
        throws DocumentException, IOException {
    final Paragraph paragraph = new Paragraph(getDefaultCell().getLeading() + cellFont.getSize());
    paragraph.setIndentationLeft(margin);
    if (context.getParentCounter().getIconName() != null) {
        paragraph.add(new Chunk(getImage(context.getParentCounter().getIconName()), 0, -1));
    }/* www .j  ava  2 s  . c om*/
    paragraph.add(new Phrase(context.getCompleteRequestName(), cellFont));
    cell.addElement(paragraph);
}

From source file:net.bull.javamelody.internal.web.pdf.PdfMBeansReport.java

License:Apache License

private void writeAttributes(MBeanNode mbean) throws DocumentException {
    final String description = mbean.getDescription();
    final List<MBeanAttribute> attributes = mbean.getAttributes();
    if (description != null || !attributes.isEmpty()) {
        currentTable = createAttributesTable();
        if (description != null) {
            currentTable.getDefaultCell().setColspan(3);
            addCell('(' + description + ')');
            currentTable.getDefaultCell().setColspan(1);
        }// w  w  w  .j a v  a  2s. c om
        for (final MBeanAttribute attribute : attributes) {
            writeAttribute(attribute);
        }
        final Paragraph paragraph = new Paragraph();
        paragraph.setIndentationLeft(margin);
        paragraph.add(currentTable);
        addToDocument(paragraph);
        addText("\n");
    }
}

From source file:net.bull.javamelody.internal.web.pdf.PdfMBeansReport.java

License:Apache License

private void addText(String text) throws DocumentException {
    final Paragraph paragraph = new Paragraph(text, normalFont);
    paragraph.setIndentationLeft(margin);
    addToDocument(paragraph);/*from   w  w w.j a va  2 s  .  co  m*/
}

From source file:net.bull.javamelody.internal.web.pdf.PdfRequestAndGraphDetailReport.java

License:Apache License

@Override
void toPdf() throws DocumentException, IOException {
    if (request != null) {
        if (request.getRumData() != null && request.getRumData().getHits() != 0) {
            writeRequestRumData();//from  ww  w .j a v  a2 s .c  o  m
        }

        writeHeader();

        writeRequests();

        addTableToDocument();

        if (JdbcWrapper.SINGLETON.getSqlCounter().isRequestIdFromThisCounter(request.getId())
                && !request.getName().toLowerCase(Locale.ENGLISH).startsWith("alter ")) {
            // inutile d'essayer d'avoir le plan d'excution des requtes sql
            // telles que "alter session set ..." (cf issue 152)
            writeSqlRequestExplainPlan();
        }
    }

    if (isGraphDisplayed()) {
        writeGraph();
    }

    if (request != null && request.getStackTrace() != null) {
        final Paragraph paragraph = new Paragraph("\n", cellFont);
        paragraph.setIndentationLeft(20);
        paragraph.setIndentationRight(20);
        paragraph.add(new Phrase("Stack-trace\n", boldFont));
        paragraph.add(new Phrase(request.getStackTrace().replace("\t", "        "), cellFont));
        addToDocument(paragraph);
    }
}

From source file:net.bull.javamelody.internal.web.pdf.PdfRequestAndGraphDetailReport.java

License:Apache License

private void writeRequest(CounterRequest childRequest, float executionsByRequest, boolean allChildHitsDisplayed)
        throws IOException, DocumentException {
    final PdfPCell defaultCell = getDefaultCell();
    defaultCell.setHorizontalAlignment(Element.ALIGN_LEFT);
    final Paragraph paragraph = new Paragraph(defaultCell.getLeading() + cellFont.getSize());
    if (executionsByRequest != -1) {
        paragraph.setIndentationLeft(5);
    }/*ww  w.  j  a v  a  2 s .c om*/
    final Counter parentCounter = getCounterByRequestId(childRequest);
    if (parentCounter != null && parentCounter.getIconName() != null) {
        paragraph.add(new Chunk(getSmallImage(parentCounter.getIconName()), 0, -1));
    }
    paragraph.add(new Phrase(childRequest.getName(), cellFont));
    final PdfPCell requestCell = new PdfPCell();
    requestCell.addElement(paragraph);
    requestCell.setGrayFill(defaultCell.getGrayFill());
    requestCell.setPaddingTop(defaultCell.getPaddingTop());
    addCell(requestCell);

    defaultCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    if (executionsByRequest != -1) {
        addCell(nbExecutionsFormat.format(executionsByRequest));
    } else {
        addCell("");
    }
    writeRequestValues(childRequest, allChildHitsDisplayed);
}