Example usage for com.lowagie.text Font ITALIC

List of usage examples for com.lowagie.text Font ITALIC

Introduction

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

Prototype

int ITALIC

To view the source code for com.lowagie.text Font ITALIC.

Click Source Link

Document

this is a possible style.

Usage

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

License:Apache License

/**
 * //from  w w  w .  ja va 2s  .  c o 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

/**
 * /*from w ww.  j a va  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 .  j  a va2  s  .c o m
 * @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:ilarkesto.integration.itext.Paragraph.java

License:Open Source License

private int createStyle(FontStyle fontStyle) {
    int style = Font.NORMAL;
    if (fontStyle.isItalic() && fontStyle.isBold()) {
        style = Font.BOLDITALIC;/*from  w  w  w .j a  v a 2s .co m*/
    } else if (fontStyle.isItalic()) {
        style = Font.ITALIC;
    } else if (fontStyle.isBold()) {
        style = Font.BOLD;
    }
    return style;
}

From source file:jm.nom.clas.Carnet.java

public void imprimir(HttpServletResponse response, ResultSet rsCarnets, String path) {
    response.setContentType("application/pdf");
    response.setHeader("Pragma", "no-cache");
    response.setHeader("Expires", "Mon, 01 Jan 2001 00:00:01 GMT");
    response.setHeader("Cache-Control", "no-store");
    response.setHeader("Cache-Control", "must-revalidate");
    response.setHeader("Cache-Control", "no-cache");

    /*try{/*from   w w  w. j a va 2 s  .  com*/
        rsCarnets = objEmpleado.getCarnets(id);
        if(rsCarnets.next()){
            id_sucursal = ((rsCarnets.getString("id_sucursal")!=null) ? rsCarnets.getString("id_sucursal") : "");
            id_instalacion = ((rsCarnets.getString("id_instalacion")!=null) ? rsCarnets.getString("id_instalacion") : "");
            serie_factura = ((rsCarnets.getString("serie_factura")!=null) ? rsCarnets.getString("serie_factura") : "");
            num_factura = ((rsCarnets.getString("num_factura")!=null) ? rsCarnets.getString("num_factura") : "");
            razon_social = ((rsCarnets.getString("razon_social")!=null) ? rsCarnets.getString("razon_social") : "CONSUMIDOR FINAL");
            fecha_emision = ((rsCarnets.getString("fecha_emision")!=null) ? Fecha.ISOaSQL(rsCarnets.getString("fecha_emision")) : "");
            direccion = ((rsCarnets.getString("direccion")!=null) ? rsCarnets.getString("direccion") : "");
            vendedor = ((rsCarnets.getString("vendedor")!=null) ? rsCarnets.getString("vendedor") : "");
            total = ((rsCarnets.getString("total")!=null) ? rsCarnets.getString("total") : "0.00");
            de_activo = ((rsCarnets.getString("de_activo")!=null) ? rsCarnets.getBoolean("de_activo") : false);
            rsCarnets.close();
        }
    }catch(Exception ie){
        ie.printStackTrace();
    }*/
    try {
        /* inicio PDF */
        Document document = new Document(PageSize.A4.rotate());// paso 1
        document.setMargins(-47, 0, 38, 0); /*Izquierda, derecha, tope, pie */

        PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // paso 2
        writer.setPageEvent(new Carnet(this._dir));
        document.open(); // paso 3

        //writer.addJavaScript("this.print(false);", false); // Para enviar a la impresora automticamente.

        /* todo el cuerpo del doc es el paso 4 */

        //PdfPTable tbl = new PdfPTable(new float[]{40f,60f});
        PdfPTable tbl = new PdfPTable(4);
        int i = 0;
        try {
            //rsCarnets = objEmpleado.getCarnets(id);
            while (rsCarnets.next()) {
                PdfPTable tbl1 = new PdfPTable(1);
                PdfPTable tbl2 = new PdfPTable(new float[] { 90f, 5f, 5f });
                String foto = ((rsCarnets.getString("padre_nombre") != null)
                        ? rsCarnets.getString("padre_nombre")
                        : "");
                //_dir="C:\\Users\\SoulGael\\Documents\\NetBeansProjects\\trunk\\saitel\\build\\web\\img\\luis.jpg";

                tbl1.addCell(Addons.setCeldaPDFBottom(" ", Font.HELVETICA, 10, Font.NORMAL, Element.ALIGN_LEFT,
                        0, 26, 0));
                tbl1.addCell(Addons.setLogoCarnet(_dir + foto, 79, 103));
                //tbl1.addCell(Addons.setLogoCarnet(_dir,79,103));
                String nombre = ((rsCarnets.getString("nombre") != null) ? rsCarnets.getString("nombre") : "");
                String apellidos = ((rsCarnets.getString("apellido") != null) ? rsCarnets.getString("apellido")
                        : "");
                String cargo = ((rsCarnets.getString("cargo") != null) ? rsCarnets.getString("cargo") : "");
                ;
                String[] nombresArray = nombre.split(" ");
                String[] apellidosArray = apellidos.split(" ");
                String n_completos = nombresArray[0] + " " + apellidosArray[0];
                String CI = ((rsCarnets.getString("dni") != null) ? rsCarnets.getString("dni") : "");
                ;
                String sangre = ((rsCarnets.getString("tipo_sangre") != null)
                        ? rsCarnets.getString("tipo_sangre")
                        : "");
                ;
                String carnet = ((rsCarnets.getString("carnet") != null) ? rsCarnets.getString("carnet") : "");
                //String carnet="A,B,C,D,E,F,G";
                Color A = Color.WHITE;
                Color B = Color.WHITE;
                Color C = Color.WHITE;
                Color D = Color.WHITE;
                Color E = Color.WHITE;
                Color F = Color.WHITE;
                Color G = Color.WHITE;

                String[] carnetArray = carnet.split(",");
                for (int j = 0; j < carnetArray.length; j++) {
                    if (carnetArray[j].equals("A")) {
                        A = Color.ORANGE;
                        j++;
                        if (j > carnetArray.length - 1)
                            j = carnetArray.length - 1;
                    }
                    if (carnetArray[j].equals("B")) {
                        B = Color.ORANGE;
                        j++;
                        if (j > carnetArray.length - 1)
                            j = carnetArray.length - 1;
                    }
                    if (carnetArray[j].equals("C")) {
                        C = Color.ORANGE;
                        ;
                        j++;
                        if (j > carnetArray.length - 1)
                            j = carnetArray.length - 1;
                    }
                    if (carnetArray[j].equals("D")) {
                        D = Color.ORANGE;
                        ;
                        j++;
                        if (j > carnetArray.length - 1)
                            j = carnetArray.length - 1;
                    }
                    if (carnetArray[j].equals("E")) {
                        E = Color.ORANGE;
                        ;
                        j++;
                        if (j > carnetArray.length - 1)
                            j = carnetArray.length - 1;
                    }
                    if (carnetArray[j].equals("F")) {
                        F = Color.ORANGE;
                        ;
                        j++;
                        if (j > carnetArray.length - 1)
                            j = carnetArray.length - 1;
                    }
                    if (carnetArray[j].equals("G")) {
                        G = Color.ORANGE;
                        ;
                        j++;
                        if (j > carnetArray.length - 1)
                            j = carnetArray.length - 1;
                    }
                    break;
                }

                tbl1.addCell(Addons.setCeldaPDFBottom(" ", Font.ITALIC, 7, Font.BOLD, Element.ALIGN_CENTER, 0,
                        0, 0));
                tbl1.addCell(Addons.setCeldaPDFBottom(n_completos, Font.ITALIC, 13, Font.BOLD,
                        Element.ALIGN_CENTER, 0, 0, 0));
                tbl1.addCell(Addons.setCeldaPDFBottom(cargo, Font.ITALIC, 12, Font.BOLD, Element.ALIGN_CENTER,
                        0, 0, 0));
                tbl1.addCell(Addons.setCeldaPDFBottom(CI, Font.ITALIC, 12, Font.BOLD, Element.ALIGN_CENTER, 0,
                        0, 0));
                tbl1.addCell(Addons.setCeldaPDFBottom(sangre, Font.ITALIC, 12, Font.BOLD, Element.ALIGN_CENTER,
                        0, 0, 0));

                tbl2.addCell(
                        Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 7, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 3));
                tbl2.addCell(
                        Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 7, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 3));
                tbl2.addCell(
                        Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 7, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 3));
                tbl2.addCell(Addons.setCeldaPDFCarnet("  LICENCIA INTERNA DE ", Font.ITALIC, 9, Font.BOLD,
                        Element.ALIGN_CENTER, 0, 0, 3));
                tbl2.addCell(Addons.setCeldaPDFCarnet("  PREVENCION DE RIESGOS", Font.ITALIC, 9, Font.BOLD,
                        Element.ALIGN_CENTER, 0, 0, 3));
                tbl2.addCell(Addons.setCeldaPDFCarnet("   Con la induccin recibida y aprobada usted",
                        Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 3));
                tbl2.addCell(Addons.setCeldaPDFCarnet("   est autorizado para:", Font.ITALIC, 8, Font.BOLD,
                        Element.ALIGN_LEFT, 0, 0, 3));
                tbl2.addCell(
                        Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 3));
                tbl2.addCell(Addons.setCeldaPDFCarnet("      a. Trabajo de Oficina.", Font.ITALIC, 8, Font.BOLD,
                        Element.ALIGN_LEFT, 0, 2, 0));
                tbl2.addCell(Addons.setCeldaPDFCarnetOpciones(" ", Font.ITALIC, 8, Font.BOLD,
                        Element.ALIGN_CENTER, 1, 2, 0, A));
                tbl2.addCell(
                        Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0));

                tbl2.addCell(Addons.setCeldaPDFCarnet("      b. Trabajo de Marketing y propaganda", Font.ITALIC,
                        8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0));
                tbl2.addCell(Addons.setCeldaPDFCarnetOpciones(" ", Font.ITALIC, 8, Font.BOLD,
                        Element.ALIGN_CENTER, 1, 2, 0, B));
                tbl2.addCell(
                        Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0));

                tbl2.addCell(Addons.setCeldaPDFCarnet("      c. Trabajo de mantenimiento y limpieza",
                        Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0));
                tbl2.addCell(Addons.setCeldaPDFCarnetOpciones(" ", Font.ITALIC, 8, Font.BOLD,
                        Element.ALIGN_CENTER, 1, 2, 0, C));
                tbl2.addCell(
                        Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0));

                tbl2.addCell(Addons.setCeldaPDFCarnet("      d. Trabajo de instalaciones menores a los ",
                        Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 0));
                tbl2.addCell(Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_CENTER, 0,
                        0, 2));
                tbl2.addCell(Addons.setCeldaPDFCarnet("      ocho metros sobre el nivel.", Font.ITALIC, 8,
                        Font.BOLD, Element.ALIGN_LEFT, 0, 0, 0));
                tbl2.addCell(Addons.setCeldaPDFCarnetOpciones(" ", Font.ITALIC, 8, Font.BOLD,
                        Element.ALIGN_CENTER, 1, 0, 0, D));
                tbl2.addCell(
                        Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0));
                tbl2.addCell(Addons.setCeldaPDFCarnet("      (Domicilios, postes, cableado)", Font.ITALIC, 8,
                        Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0));
                tbl2.addCell(Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_CENTER, 0,
                        2, 2));

                tbl2.addCell(Addons.setCeldaPDFCarnet("      e. Trabajo de instalaciones, antenas,",
                        Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 0));
                tbl2.addCell(Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_CENTER, 0,
                        0, 2));
                tbl2.addCell(Addons.setCeldaPDFCarnet("      infraestructura mayores a los ocho", Font.ITALIC,
                        8, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 0));
                tbl2.addCell(Addons.setCeldaPDFCarnetOpciones(" ", Font.ITALIC, 8, Font.BOLD,
                        Element.ALIGN_CENTER, 1, 0, 0, E));
                tbl2.addCell(
                        Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0));
                tbl2.addCell(Addons.setCeldaPDFCarnet("      metros sobre el nivel", Font.ITALIC, 8, Font.BOLD,
                        Element.ALIGN_LEFT, 0, 2, 0));
                tbl2.addCell(Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_CENTER, 0,
                        2, 2));

                tbl2.addCell(Addons.setCeldaPDFCarnet("      f. Planes de emergencia y contingencia",
                        Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0));
                tbl2.addCell(Addons.setCeldaPDFCarnetOpciones(" ", Font.ITALIC, 8, Font.BOLD,
                        Element.ALIGN_CENTER, 1, 2, 0, F));
                tbl2.addCell(
                        Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0));

                tbl2.addCell(Addons.setCeldaPDFCarnet("      g. Planes de rescate", Font.ITALIC, 8, Font.BOLD,
                        Element.ALIGN_LEFT, 0, 2, 0));
                tbl2.addCell(Addons.setCeldaPDFCarnetOpciones(" ", Font.ITALIC, 8, Font.BOLD,
                        Element.ALIGN_CENTER, 1, 2, 0, G));
                tbl2.addCell(
                        Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0));

                tbl2.addCell(
                        Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 3));
                tbl2.addCell(
                        Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 3));
                tbl2.addCell(
                        Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 10, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 3));
                tbl2.addCell(Addons.setCeldaPDFCarnet("Ing. FREDDY ROSERO", Font.ITALIC, 8, Font.BOLD,
                        Element.ALIGN_CENTER, 0, 0, 3, Color.BLUE));
                tbl2.addCell(Addons.setCeldaPDFCarnet("GERENTE", Font.ITALIC, 8, Font.BOLD,
                        Element.ALIGN_CENTER, 0, 0, 3, Color.BLUE));
                tbl2.addCell(Addons.setCeldaPDFCarnet("Fecha de Expedicin: Mayo 2015", Font.ITALIC, 5,
                        Font.BOLD, Element.ALIGN_CENTER, 0, 0, 3, Color.BLUE));
                tbl2.addCell(Addons.setCeldaPDFCarnet("Fecha de Caducidad: Mayo 2016", Font.ITALIC, 5,
                        Font.BOLD, Element.ALIGN_CENTER, 0, 0, 3, Color.BLUE));
                /* tbl1.addCell(Addons.setCeldaPDF(((rsCarnets.getString("nombres")!=null) ? rsCarnets.getString("nombres") : ""), Font.HELVETICA, 10, Font.NORMAL, Element.ALIGN_LEFT, 1));
                tbl1.addCell(Addons.setCeldaPDF(((rsCarnets.getString("rol")!=null) ? rsCarnets.getString("rol") : ""), Font.HELVETICA, 10, Font.NORMAL, Element.ALIGN_LEFT, 1));
                        
                tbl1.addCell(Addons.setCeldaPDF(((rsCarnets.getString("dni")!=null) ? rsCarnets.getString("dni") : ""), Font.HELVETICA, 10, Font.NORMAL, Element.ALIGN_LEFT, 1));
                tbl1.addCell(Addons.setCeldaPDF(((rsCarnets.getString("tipo_sangre")!=null) ? rsCarnets.getString("tipo_sangre") : ""), Font.HELVETICA, 10, Font.NORMAL, Element.ALIGN_LEFT, 1));
                        
                String idcarnet=(rsCarnets.getString("id_empleado")!=null) ? rsCarnets.getString("id_empleado") : "";*/

                tbl.addCell(Addons.setCeldaPDF(tbl1, 0, 0));
                tbl.addCell(Addons.setCeldaPDF(tbl2, 0, 0));
                if (i % 2 != 0) {
                    tbl1.addCell(
                            Addons.setCeldaPDF(" ", Font.ITALIC, 10, Font.BOLD, Element.ALIGN_LEFT, 0, 16, 3));
                }
                i++;
            }
            if (i % 2 != 0) {
                tbl.addCell(" ");
                tbl.addCell(" ");
            }

            /*Archivo archivo = new Archivo(_ip, _puerto, _db, _usuario, _clave);
                //path = path.substring(0, path.lastIndexOf("/"));
                String carnet = path + "/img/" + archivo.getArchivo(_dir, "vta_empleado", idcarnet, "padre_nombre", "foto");
                archivo.cerrar();
                Image imagen = null;
                try{
                    imagen = Image.getInstance(carnet);
                    imagen.scaleAbsolute(50, 70);
                    PdfPCell celdaImg = new PdfPCell(imagen);
                    celdaImg.setBorderWidth(0);
                    celdaImg.setPadding(0);
                    tbl.addCell(celdaImg);
                    document.add(tbl1);
                }catch(Exception e){
                    tbl.addCell(" ");
                }*/

        } catch (Exception e) {
            e.printStackTrace();
        }
        document.add(tbl);

        document.close(); // paso 5
        /* fin PDF */

    } catch (IllegalStateException ie) {
        ie.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:mesquite.lib.MesquitePDFFile.java

License:Open Source License

/**
@arg s String holds the text that the pdf file will contain
@arg font java.awt.Font the font is specified this way for compatibility with the similar method in MesquitePrintJob
 *///  w w w  .  j  a  v  a 2s.c  o m
public void printText(String s, java.awt.Font font) {
    final String exceptionMessage = "Error, an exception occurred while creating the pdf text document: ";
    if (s == null || font == null)
        return;

    //do the translation from logical to physical font here      
    //currently, the only font this method ever gets called with is "Monospaced",PLAIN,10.  So the
    //translation effort here will be minimal      
    int desiredFontFamily; // "Monospaced" isn't defined in com.lowagie.text.Font
    if (font.getFamily().equals("Monospaced"))
        desiredFontFamily = com.lowagie.text.Font.COURIER;
    else
        desiredFontFamily = com.lowagie.text.Font.TIMES_ROMAN;
    com.lowagie.text.Font textFont;
    switch (font.getStyle()) {
    case java.awt.Font.BOLD: {
        textFont = new com.lowagie.text.Font(desiredFontFamily, font.getSize(), com.lowagie.text.Font.BOLD);
        break;
    }
    case java.awt.Font.ITALIC: {
        textFont = new com.lowagie.text.Font(desiredFontFamily, font.getSize(), com.lowagie.text.Font.ITALIC);
        break;
    }
    case java.awt.Font.PLAIN: {
        textFont = new com.lowagie.text.Font(desiredFontFamily, font.getSize(), com.lowagie.text.Font.NORMAL);
        break;
    }
    default: {
        textFont = new com.lowagie.text.Font(desiredFontFamily, font.getSize(),
                com.lowagie.text.Font.BOLDITALIC);
    }
    }
    document = new Document();
    try {
        PdfWriter.getInstance(document, new FileOutputStream(pdfPathString));
        addMetaData(document);
        document.open();
        document.add(new Paragraph(s, textFont));
    } catch (DocumentException de) {
        MesquiteTrunk.mesquiteTrunk.alert(exceptionMessage + de.getMessage());
    } catch (IOException ioe) {
        MesquiteTrunk.mesquiteTrunk.alert(exceptionMessage + ioe.getMessage());
    }
    this.end();
}

From source file:net.sf.jasperreports.engine.export.JRPdfExporter.java

License:LGPL

/**
 *
 *//*from w  ww. j a v  a2  s . c  o m*/
protected Font getFont(Map attributes) {
    JRFont jrFont = new JRBaseFont(attributes);

    Exception initialException = null;

    Color forecolor = (Color) attributes.get(TextAttribute.FOREGROUND);

    Font font = null;
    PdfFont pdfFont = null;
    FontKey key = new FontKey(jrFont.getFontName(), jrFont.isBold(), jrFont.isItalic());

    if (fontMap != null && fontMap.containsKey(key)) {
        pdfFont = (PdfFont) fontMap.get(key);
    } else {
        pdfFont = new PdfFont(jrFont.getPdfFontName(), jrFont.getPdfEncoding(), jrFont.isPdfEmbedded());
    }

    try {
        font = FontFactory.getFont(pdfFont.getPdfFontName(), pdfFont.getPdfEncoding(), pdfFont.isPdfEmbedded(),
                jrFont.getFontSize(),
                (pdfFont.isPdfSimulatedBold() ? Font.BOLD : 0)
                        | (pdfFont.isPdfSimulatedItalic() ? Font.ITALIC : 0)
                        | (jrFont.isUnderline() ? Font.UNDERLINE : 0)
                        | (jrFont.isStrikeThrough() ? Font.STRIKETHRU : 0),
                forecolor);

        // check if FontFactory didn't find the font
        if (font.getBaseFont() == null && font.family() == Font.UNDEFINED) {
            font = null;
        }
    } catch (Exception e) {
        initialException = e;
    }

    if (font == null) {
        byte[] bytes = null;

        try {
            bytes = JRLoader.loadBytesFromLocation(pdfFont.getPdfFontName(), classLoader, urlHandlerFactory,
                    fileResolver);
        } catch (JRException e) {
            throw new JRRuntimeException("Could not load the following font : " + "\npdfFontName   : "
                    + pdfFont.getPdfFontName() + "\npdfEncoding   : " + pdfFont.getPdfEncoding()
                    + "\nisPdfEmbedded : " + pdfFont.isPdfEmbedded(), initialException);
        }

        BaseFont baseFont = null;

        try {
            baseFont = BaseFont.createFont(pdfFont.getPdfFontName(), pdfFont.getPdfEncoding(),
                    pdfFont.isPdfEmbedded(), true, bytes, null);
        } catch (DocumentException e) {
            throw new JRRuntimeException(e);
        } catch (IOException e) {
            throw new JRRuntimeException(e);
        }

        font = new Font(baseFont, jrFont.getFontSize(),
                ((pdfFont.isPdfSimulatedBold()) ? Font.BOLD : 0)
                        | ((pdfFont.isPdfSimulatedItalic()) ? Font.ITALIC : 0)
                        | (jrFont.isUnderline() ? Font.UNDERLINE : 0)
                        | (jrFont.isStrikeThrough() ? Font.STRIKETHRU : 0),
                forecolor);
    }

    return font;
}

From source file:nl.dykema.jxmlnote.report.pdf.PdfChunk.java

License:Open Source License

public void setFont(Font g) {
    Font f = new Font(g);
    int chst = 0;
    if (_bold) {/* www.  ja  v a 2 s.c  o m*/
        chst += Font.BOLD;
    }
    if (_italic) {
        chst += Font.ITALIC;
    }
    if (_underline) {
        chst += Font.UNDERLINE;
    }
    f.setStyle(chst);
    super.setFont(f);
}

From source file:nl.dykema.jxmlnote.report.pdf.PdfParagraph.java

License:Open Source License

public Paragraph setStyle(XMLNoteParStyle style) {
    //System.out.println(super.getLeading()+","+super.getMultipliedLeading());
    _style = style;// w w w  .  j a v a  2s . co  m
    if (style == null) {
        return this;
    }

    int chst = 0;
    if (style.bold()) {
        chst += Font.BOLD;
    }
    if (style.italics()) {
        chst += Font.ITALIC;
    }
    if (style.underline()) {
        chst += Font.UNDERLINE;
    }
    Font f = getFont(style.getFont());
    f.setSize(style.pointSize());
    f.setStyle(chst);
    float indentleft;
    indentleft = (float) style.leftIndent();
    super.setIndentationLeft(indentleft);
    super.setSpacingAfter(style.bottomSkip());
    super.setSpacingBefore(style.topSkip());
    //super.setLeading(0.0f); DO DIT NIET!

    //System.out.println(super.getLeading()+","+super.getMultipliedLeading());
    int p1align = getAlign(style);
    super.setAlignment(p1align);
    super.setFont(f);
    //System.out.println(super.getLeading()+","+super.getMultipliedLeading());
    super.setLeading(0.0f, 1.2f);
    //System.out.println(super.getLeading()+","+super.getMultipliedLeading());

    return this;
}

From source file:org.apache.maven.doxia.module.itext.ITextFont.java

License:Apache License

/**
 * Add italic style to the current style
 */
public void addItalic() {
    this.currentStyle += Font.ITALIC;
}