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

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

Introduction

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

Prototype

public void setBorderColorBottom(Color borderColorBottom) 

Source Link

Document

Sets the color of the bottom border.

Usage

From source file:com.krawler.spring.exportFunctionality.exportMPXDAOImpl.java

License:Open Source License

public void addGroupRow(String groupText, String currencyid, PdfPTable table, String[] dataIndexArr)
        throws JSONException, SessionExpiredException {
    Paragraph para = new Paragraph(fontFamilySelector.process(groupText, FontContext.REPORT_TITLE));
    PdfPCell h1 = new PdfPCell(para);
    if (config.getBoolean("gridBorder")) {
        h1.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT);
    } else {/* ww  w. ja  v a 2  s. co m*/
        h1.setBorder(PdfPCell.BOTTOM);
    }
    h1.setBorderWidthBottom(1);
    h1.setPadding(4);
    h1.setBorderColor(Color.GRAY);
    h1.setBorderColorBottom(Color.DARK_GRAY);
    h1.setHorizontalAlignment(Element.ALIGN_LEFT);
    h1.setVerticalAlignment(Element.ALIGN_LEFT);
    h1.setColspan(dataIndexArr.length + 1);
    table.addCell(h1);
}

From source file:fr.opensagres.odfdom.converter.pdf.internal.stylable.StyleUtils.java

License:Open Source License

public static void applyStyles(StyleBorder border, PdfPCell cell) {
    if (border == null) {
        return;/*from w  w  w.  ja va 2  s .co  m*/
    }
    switch (border.getBorderType()) {
    case ALL:
        // border
        if (border.isNoBorder()) {
            cell.disableBorderSide(PdfPCell.TOP);
            cell.disableBorderSide(PdfPCell.BOTTOM);
            cell.disableBorderSide(PdfPCell.RIGHT);
            cell.disableBorderSide(PdfPCell.LEFT);
        } else {
            cell.enableBorderSide(PdfPCell.TOP);
            cell.enableBorderSide(PdfPCell.BOTTOM);
            cell.enableBorderSide(PdfPCell.RIGHT);
            cell.enableBorderSide(PdfPCell.LEFT);
            // border-color
            Color color = border.getColor();
            if (color != null) {
                cell.setBorderColor(color);
            }
            // border-width
            Float width = border.getWidth();
            if (width != null) {
                cell.setBorderWidth(width);
            }
        }
        break;
    case BOTTOM:
        // border-bottom
        if (border.isNoBorder()) {
            cell.disableBorderSide(PdfPCell.BOTTOM);
        } else {
            cell.enableBorderSide(PdfPCell.BOTTOM);
            // border-bottom-color
            Color color = border.getColor();
            if (color != null) {
                cell.setBorderColorBottom(color);
            }
            // border-bottom-width
            Float width = border.getWidth();
            if (width != null) {
                cell.setBorderWidthBottom(width);
            }
        }
        break;
    case LEFT:
        // border-left
        if (border.isNoBorder()) {
            cell.disableBorderSide(PdfPCell.LEFT);
        } else {
            cell.enableBorderSide(PdfPCell.LEFT);
            // border-left-color
            Color color = border.getColor();
            if (color != null) {
                cell.setBorderColorLeft(color);
            }
            // border-left-width
            Float width = border.getWidth();
            if (width != null) {
                cell.setBorderWidthLeft(width);
            }
        }
        break;
    case RIGHT:
        // border-right
        if (border.isNoBorder()) {
            cell.disableBorderSide(PdfPCell.RIGHT);
        } else {
            cell.enableBorderSide(PdfPCell.RIGHT);
            // border-right-color
            Color color = border.getColor();
            if (color != null) {
                cell.setBorderColorRight(color);
            }
            // border-right-width
            Float width = border.getWidth();
            if (width != null) {
                cell.setBorderWidthRight(width);
            }
        }
        break;
    case TOP:
        // border-top
        if (border.isNoBorder()) {
            cell.disableBorderSide(PdfPCell.TOP);
        } else {
            cell.enableBorderSide(PdfPCell.TOP);
            // border-top-color
            Color color = border.getColor();
            if (color != null) {
                cell.setBorderColorTop(color);
            }
            // border-top-width
            Float width = border.getWidth();
            if (width != null) {
                cell.setBorderWidthTop(width);
            }
        }
        break;
    }

}

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

License:Apache License

/**
 * //from  w  ww .ja  va 2 s. com
 * @param document pdf
 */
public void creerPdfCalendrier(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 libells du pied de page:
    String partie1 = applicationContext.getMessage("pdf.calendrier.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;
        }
    }

    //cration 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);
        }

        //nouveau paragraphe
        Paragraph p = new Paragraph(
                applicationContext.getMessage("pdf.calendrier.title", null, Locale.getDefault()).toUpperCase()
                        + "\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 Calendrier
        PdfPTable table = new PdfPTable(1);
        table.setWidthPercentage(98);
        PdfPCell cell = new PdfPCell(new Paragraph(applicationContext
                .getMessage("pdf.calendrier.subtitle", null, Locale.getDefault()).toUpperCase() + " ", header));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setBackgroundColor(new Color(153, 153, 255));
        table.addCell(cell);

        PdfPTable table2;

        boolean affNumPlaceExamen = configController.isAffNumPlaceExamen();

        if (affNumPlaceExamen) {
            table2 = new PdfPTable(7);
            table2.setWidthPercentage(98);
            int[] tabWidth = { 15, 10, 10, 40, 30, 10, 60 };
            table2.setWidths(tabWidth);
        } else {
            table2 = new PdfPTable(6);
            table2.setWidthPercentage(98);
            int[] tabWidth = { 15, 10, 10, 45, 30, 65 };
            table2.setWidths(tabWidth);
        }

        Paragraph p1 = new Paragraph(applicationContext.getMessage("pdf.date", null, Locale.getDefault()),
                normalbig);
        Paragraph p2 = new Paragraph(applicationContext.getMessage("pdf.heure", null, Locale.getDefault()),
                normalbig);
        Paragraph p3 = new Paragraph(applicationContext.getMessage("pdf.duree", null, Locale.getDefault()),
                normalbig);
        Paragraph p4 = new Paragraph(applicationContext.getMessage("pdf.batiment", null, Locale.getDefault()),
                normalbig);
        Paragraph p5 = new Paragraph(applicationContext.getMessage("pdf.salle", null, Locale.getDefault()),
                normalbig);
        Paragraph p6 = new Paragraph(applicationContext.getMessage("pdf.place", null, Locale.getDefault()),
                normalbig);
        Paragraph p7 = new Paragraph(applicationContext.getMessage("pdf.examen", null, Locale.getDefault()),
                normalbig);

        PdfPCell ct1 = new PdfPCell(p1);
        PdfPCell ct2 = new PdfPCell(p2);
        PdfPCell ct3 = new PdfPCell(p3);
        PdfPCell ct4 = new PdfPCell(p4);
        PdfPCell ct5 = new PdfPCell(p5);
        PdfPCell ct6 = new PdfPCell(p6);
        PdfPCell ct7 = new PdfPCell(p7);

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

        table2.addCell(ct1);
        table2.addCell(ct2);
        table2.addCell(ct3);
        table2.addCell(ct4);
        table2.addCell(ct5);
        if (affNumPlaceExamen)
            table2.addCell(ct6);
        table2.addCell(ct7);

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

            Paragraph pa2 = new Paragraph(etudiant.getCalendrier().get(i).getHeure(), normal);
            PdfPCell celltext2 = new PdfPCell(pa2);
            celltext2.setBorder(Rectangle.NO_BORDER);

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

            Paragraph pa4 = new Paragraph(etudiant.getCalendrier().get(i).getBatiment(), normal);
            PdfPCell celltext4 = new PdfPCell(pa4);
            celltext4.setBorder(Rectangle.NO_BORDER);

            Paragraph pa5 = new Paragraph(etudiant.getCalendrier().get(i).getSalle(), normal);
            PdfPCell celltext5 = new PdfPCell(pa5);
            celltext5.setBorder(Rectangle.NO_BORDER);

            Paragraph pa6 = new Paragraph(etudiant.getCalendrier().get(i).getPlace(), normal);
            PdfPCell celltext6 = new PdfPCell(pa6);
            celltext6.setBorder(Rectangle.NO_BORDER);

            Paragraph pa7 = new Paragraph(etudiant.getCalendrier().get(i).getEpreuve(), normal);
            PdfPCell celltext7 = new PdfPCell(pa7);
            celltext7.setBorder(Rectangle.NO_BORDER);

            table2.addCell(celltext);
            table2.addCell(celltext2);
            table2.addCell(celltext3);
            table2.addCell(celltext4);
            table2.addCell(celltext5);
            if (affNumPlaceExamen)
                table2.addCell(celltext6);
            table2.addCell(celltext7);

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

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

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

}

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

License:Apache License

/**
 * /*w  ww  .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

/**
 * /* w  ww . 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.Cell.java

License:Open Source License

@Override
public Element getITextElement() {
    PdfPCell cell = new PdfPCell();

    cell.setBorderColorTop(getBorderTopColor());
    cell.setBorderColorBottom(getBorderBottomColor());
    cell.setBorderColorLeft(getBorderLeftColor());
    cell.setBorderColorRight(getBorderRightColor());
    cell.setBorderWidthTop(APdfBuilder.mmToPoints(getBorderTopWidth()));
    cell.setBorderWidthBottom(APdfBuilder.mmToPoints(getBorderBottomWidth()));
    cell.setBorderWidthLeft(APdfBuilder.mmToPoints(getBorderLeftWidth()));
    cell.setBorderWidthRight(APdfBuilder.mmToPoints(getBorderRightWidth()));
    cell.setUseBorderPadding(false);/*  w  ww. ja v a 2s . c o  m*/

    cell.setPadding(0);
    cell.setPaddingTop(APdfBuilder.mmToPoints(getPaddingTop()));
    cell.setPaddingBottom(APdfBuilder.mmToPoints(getPaddingBottom()));
    cell.setPaddingLeft(APdfBuilder.mmToPoints(getPaddingLeft()));
    cell.setPaddingRight(APdfBuilder.mmToPoints(getPaddingRight()));

    cell.setBackgroundColor(getBackgroundColor());
    cell.setExtraParagraphSpace(0);
    cell.setIndent(0);

    cell.setColspan(getColspan());
    for (ItextElement element : elements)
        cell.addElement(element.getITextElement());
    return cell;
}

From source file:jdbreport.model.io.pdf.itext2.PdfWriter.java

License:Apache License

private void assignBorders(CellStyle style, PdfPCell pdfCell) {
    pdfCell.setBorderWidth(0);/*  w ww . j a  v  a  2 s . co m*/
    if (pdfCell.getBackgroundColor() != Color.WHITE) {
        pdfCell.setBorderColor(pdfCell.getBackgroundColor());
    }
    Border border = style.getBorders(Border.LINE_LEFT);
    if (border != null) {
        pdfCell.setBorderWidthLeft(border.getLineWidth());
        pdfCell.setBorderColorLeft(border.getColor());
    }
    border = style.getBorders(Border.LINE_RIGHT);
    if (border != null) {
        pdfCell.setBorderWidthRight(border.getLineWidth());
        pdfCell.setBorderColorRight(border.getColor());
    }
    if (pdfCell.getBackgroundColor() != Color.WHITE) {
        pdfCell.setBorderWidthRight(0.5f);
    }
    border = style.getBorders(Border.LINE_TOP);
    if (border != null) {
        pdfCell.setBorderWidthTop(border.getLineWidth());
        pdfCell.setBorderColorTop(border.getColor());
    }
    border = style.getBorders(Border.LINE_BOTTOM);
    if (border != null) {
        pdfCell.setBorderWidthBottom(border.getLineWidth());
        pdfCell.setBorderColorBottom(border.getColor());
    }
    if (pdfCell.getBackgroundColor() != Color.WHITE) {
        pdfCell.setBorderWidthBottom(0.5f);
    }
}

From source file:org.apache.poi.xwpf.converter.internal.itext.stylable.StyleUtils.java

License:Open Source License

public static void applyStyles(StyleBorder border, PdfPCell cell) {
    if (border == null) {
        return;/*  w  w w .  j  a v  a2s .  com*/
    }
    switch (border.getBorderType()) {
    case ALL:
        // border
        if (border.isNoBorder()) {
            cell.disableBorderSide(PdfPCell.TOP);
            cell.disableBorderSide(PdfPCell.BOTTOM);
            cell.disableBorderSide(PdfPCell.RIGHT);
            cell.disableBorderSide(PdfPCell.LEFT);
        } else {
            cell.enableBorderSide(PdfPCell.TOP);
            cell.enableBorderSide(PdfPCell.BOTTOM);
            cell.enableBorderSide(PdfPCell.RIGHT);
            cell.enableBorderSide(PdfPCell.LEFT);
            // border-color
            Color color = border.getColor();
            if (color != null) {
                cell.setBorderColor(color);
            }
            // border-width
            BigInteger width = border.getWidth();
            if (width != null) {
                cell.setBorderWidth(dxa2points(width));
            }
        }
        break;
    case BOTTOM:
        // border-bottom
        if (border.isNoBorder()) {
            cell.disableBorderSide(PdfPCell.BOTTOM);
        } else {
            cell.enableBorderSide(PdfPCell.BOTTOM);
            // border-bottom-color
            Color color = border.getColor();
            if (color != null) {
                cell.setBorderColorBottom(color);
            }
            // border-bottom-width
            BigInteger width = border.getWidth();
            if (width != null) {
                cell.setBorderWidthBottom(dxa2points(width));
            }
        }
        break;
    case LEFT:
        // border-left
        if (border.isNoBorder()) {
            cell.disableBorderSide(PdfPCell.LEFT);
        } else {
            cell.enableBorderSide(PdfPCell.LEFT);
            // border-left-color
            Color color = border.getColor();
            if (color != null) {
                cell.setBorderColorLeft(color);
            }
            // border-left-width
            BigInteger width = border.getWidth();
            if (width != null) {
                cell.setBorderWidthLeft(dxa2points(width));
            }
        }
        break;
    case RIGHT:
        // border-right
        if (border.isNoBorder()) {
            cell.disableBorderSide(PdfPCell.RIGHT);
        } else {
            cell.enableBorderSide(PdfPCell.RIGHT);
            // border-right-color
            Color color = border.getColor();
            if (color != null) {
                cell.setBorderColorRight(color);
            }
            // border-right-width
            BigInteger width = border.getWidth();
            if (width != null) {
                cell.setBorderWidthRight(dxa2points(width));
            }
        }
        break;
    case TOP:
        // border-top
        if (border.isNoBorder()) {
            cell.disableBorderSide(PdfPCell.TOP);
        } else {
            cell.enableBorderSide(PdfPCell.TOP);
            // border-top-color
            Color color = border.getColor();
            if (color != null) {
                cell.setBorderColorTop(color);
            }
            // border-top-width
            BigInteger width = border.getWidth();
            if (width != null) {
                cell.setBorderWidthTop(dxa2points(width));
            }
        }
        break;
    }

}

From source file:org.apache.poi.xwpf.converter.internal.itext.XWPFTableUtil.java

License:Open Source License

public static void setBorder(CTBorder border, PdfPCell pdfPCell, int borderSide) {
    if (border == null) {
        return;/*from   w w  w .ja  v  a  2s . c o m*/
    }
    boolean noBorder = (STBorder.NONE == border.getVal());

    // No border
    if (noBorder) {
        pdfPCell.disableBorderSide(borderSide);
    } else {
        float size = -1;
        BigInteger borderSize = border.getSz();
        if (borderSize != null) {
            size = dxa2points(borderSize);
        }

        Color borderColor = null;
        String hexColor = getBorderColor(border);
        if (hexColor != null) {
            borderColor = ColorRegistry.getInstance().getColor("0x" + hexColor);
        }

        switch (borderSide) {
        case Rectangle.TOP:
            if (size != -1) {
                pdfPCell.setBorderWidthTop(size);
            }
            if (borderColor != null) {

                pdfPCell.setBorderColorTop(borderColor);
            }
            break;
        case Rectangle.BOTTOM:
            if (size != -1) {
                pdfPCell.setBorderWidthBottom(size);
            }
            if (borderColor != null) {
                pdfPCell.setBorderColorBottom(borderColor);
            }
            break;
        case Rectangle.LEFT:
            if (size != -1) {
                pdfPCell.setBorderWidthLeft(size);
            }
            if (borderColor != null) {
                pdfPCell.setBorderColorLeft(borderColor);
            }
            break;
        case Rectangle.RIGHT:
            if (size != -1) {
                pdfPCell.setBorderWidthRight(size);
            }
            if (borderColor != null) {
                pdfPCell.setBorderColorRight(borderColor);
            }
            break;
        }
    }
}

From source file:org.apache.poi.xwpf.converter.internal.itext.XWPFTableUtil.java

License:Open Source License

public static void setBorder(StyleBorder border, PdfPCell pdfPCell, int borderSide) {
    if (border == null) {
        return;/*from  ww w.ja va  2s.  c  o m*/
    }
    // boolean noBorder = (STBorder.NONE == border.getVal());

    // No border

    float size = -1;
    BigInteger borderSize = border.getWidth();
    if (borderSize != null) {
        size = dxa2points(borderSize);
    }

    Color borderColor = border.getColor();

    switch (borderSide) {
    case Rectangle.TOP:
        if (size != -1) {
            pdfPCell.setBorderWidthTop(size);
        }
        if (borderColor != null) {

            pdfPCell.setBorderColorTop(borderColor);
        }
        break;
    case Rectangle.BOTTOM:
        if (size != -1) {
            pdfPCell.setBorderWidthBottom(size);
        }
        if (borderColor != null) {
            pdfPCell.setBorderColorBottom(borderColor);
        }
        break;
    case Rectangle.LEFT:
        if (size != -1) {
            pdfPCell.setBorderWidthLeft(size);
        }
        if (borderColor != null) {
            pdfPCell.setBorderColorLeft(borderColor);
        }
        break;
    case Rectangle.RIGHT:
        if (size != -1) {
            pdfPCell.setBorderWidthRight(size);
        }
        if (borderColor != null) {
            pdfPCell.setBorderColorRight(borderColor);
        }
        break;
    }

}