Example usage for com.lowagie.text.pdf PdfPCell cloneNonPositionParameters

List of usage examples for com.lowagie.text.pdf PdfPCell cloneNonPositionParameters

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfPCell cloneNonPositionParameters.

Prototype

public void cloneNonPositionParameters(Rectangle rect) 

Source Link

Document

Copies each of the parameters, except the position, from a Rectangle object

Usage

From source file:com.gtdfree.test.TableBorders.java

License:Open Source License

private static PdfPCell makeCell(String text, int vAlignment, int hAlignment, Font font, float leading,
        float padding, Rectangle borders, boolean ascender, boolean descender) {
    Paragraph p = new Paragraph(text, font);
    p.setLeading(leading);/*from  w  ww.j  a v a2  s.  c  o m*/

    PdfPCell cell = new PdfPCell(p);
    cell.setLeading(leading, 0);
    cell.setVerticalAlignment(vAlignment);
    cell.setHorizontalAlignment(hAlignment);
    cell.cloneNonPositionParameters(borders);
    cell.setUseAscender(ascender);
    cell.setUseDescender(descender);
    cell.setUseBorderPadding(true);
    cell.setPadding(padding);
    return cell;
}

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

License:Apache License

/**
 * //from  w  w  w.j a  v a 2 s  .  com
 * @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();

}