Example usage for com.itextpdf.layout.element Cell Cell

List of usage examples for com.itextpdf.layout.element Cell Cell

Introduction

In this page you can find the example usage for com.itextpdf.layout.element Cell Cell.

Prototype

public Cell(int rowspan, int colspan) 

Source Link

Document

Creates a cell which takes a custom amount of cell spaces in the table.

Usage

From source file:com.asptt.plongee.resa.util.UtilsFSpdf.java

private void createTablePlongeur(Table tablePalanques, FicheSecurite fs, int i, Style s_plongeur) {
        float[] colWidths = { 25, 25, 25, 25 };
        Table tablePlongeurs = new Table(colWidths);
        tablePlongeurs.setMarginTop(0);/*ww  w .  ja  va 2 s .  c o m*/
        tablePlongeurs.setMarginBottom(0);
        tablePlongeurs.setWidthPercent(100);
        // first row
        Cell cellNom = new Cell(1, 3).add(new Paragraph("Nom"));
        cellNom.setTextAlignment(TextAlignment.CENTER);
        cellNom.setFontSize(12);
        cellNom.setPadding(5);
        cellNom.setBackgroundColor(new DeviceRgb(140, 221, 8));
        tablePlongeurs.addCell(cellNom);
        Cell cellApt = new Cell(1, 1).add(new Paragraph("Apt"));
        cellApt.setTextAlignment(TextAlignment.CENTER);
        cellApt.setFontSize(12);
        cellApt.setPadding(5);
        cellApt.setBackgroundColor(new DeviceRgb(140, 221, 8));
        tablePlongeurs.addCell(cellApt);
        if (fs.getPalanques().size() > i) {
            initTablePlongeur(fs.getPalanques().get(i), tablePlongeurs, s_plongeur);
        } else {
            initTablePlongeur(null, tablePlongeurs, s_plongeur);
        }
        tablePalanques.addCell(tablePlongeurs);
    }

From source file:com.asptt.plongee.resa.util.UtilsFSpdf.java

public void createPdfPlongee(String dest, Plongee plongee)
            throws IOException, FileNotFoundException, java.io.IOException {
        PageSize ps = PageSize.A4.rotate();
        PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
        pdfDoc.addNewPage(ps);//from   w w  w  .  jav  a2  s.  c o m
        Document doc = new Document(pdfDoc);
        float[] columnWidths = { 20, 20, 5, 10, 15, 15, 15 };
        // table : premiere table pour les parametres de la plonge
        Table table = new Table(columnWidths);
        table.setMargins(0, 0, 0, 0);
        table.setWidthPercent(100);
        // entete style pour les titres
        Style s_titre = new Style();
        PdfFont fontEntete = PdfFontFactory.createFont(FontConstants.TIMES_ROMAN);
        s_titre.setFont(fontEntete).setFontSize(12);
        s_titre.setFontColor(Color.ORANGE);
        // style pour l'entete de la table
        Style s_entete = new Style();
        PdfFont fontLibelle = PdfFontFactory.createFont(FontConstants.TIMES_ROMAN);
        s_entete.setFont(fontLibelle).setFontSize(12);
        s_entete.setFontColor(Color.BLUE);

        Paragraph entete1 = new Paragraph();
        entete1.add(new Text("Plong\u00e9e du " + ResaUtil.getJourDatePlongee(plongee.getDatePlongee()) + "    '"
                + ResaUtil.getHeurePlongee(plongee.getDatePlongee()) + "'\n").addStyle(s_titre));
        entete1.add(
                new Text("Nombre de participants " + plongee.getParticipants().size() + "\n").addStyle(s_titre));
        entete1.add(new Text("\n").addStyle(s_titre));
        entete1.add(new Text("Inscrit\n").addStyle(s_titre));

        Cell cellEntete1 = new Cell(1, 7);
        cellEntete1.add(entete1);
        cellEntete1.setBorderRight(Border.NO_BORDER);
        //        cellEntete1.setBackgroundColor(Color.BLUE);
        cellEntete1.setHorizontalAlignment(HorizontalAlignment.LEFT);
        table.addCell(cellEntete1);

        Cell cellNom = new Cell().add(new Paragraph("Nom"));
        cellNom.setTextAlignment(TextAlignment.CENTER);
        cellNom.setFontSize(8);
        cellNom.setFontColor(Color.BLACK);
        cellNom.setPadding(5);
        cellNom.setBackgroundColor(new DeviceRgb(140, 221, 8));
        table.addCell(cellNom);

        Cell cellPrenom = new Cell().add(new Paragraph("Prnom"));
        cellPrenom.setTextAlignment(TextAlignment.CENTER);
        cellPrenom.setFontSize(8);
        cellPrenom.setFontColor(Color.BLACK);
        cellPrenom.setPadding(5);
        cellPrenom.setBackgroundColor(new DeviceRgb(140, 221, 8));
        table.addCell(cellPrenom);

        Cell cellNiveau = new Cell().add(new Paragraph("Niveau"));
        cellNiveau.setTextAlignment(TextAlignment.CENTER);
        cellNiveau.setFontSize(8);
        cellNiveau.setFontColor(Color.BLACK);
        cellNiveau.setPadding(5);
        cellNiveau.setBackgroundColor(new DeviceRgb(140, 221, 8));
        table.addCell(cellNiveau);

        Cell cellAptitude = new Cell().add(new Paragraph("Aptitude"));
        cellAptitude.setTextAlignment(TextAlignment.CENTER);
        cellAptitude.setFontSize(8);
        cellAptitude.setFontColor(Color.BLACK);
        cellAptitude.setPadding(5);
        cellAptitude.setBackgroundColor(new DeviceRgb(140, 221, 8));
        table.addCell(cellAptitude);

        Cell cellTelephone1 = new Cell().add(new Paragraph("Tlphone"));
        cellTelephone1.setTextAlignment(TextAlignment.CENTER);
        cellTelephone1.setFontSize(8);
        cellTelephone1.setFontColor(Color.BLACK);
        cellTelephone1.setPadding(5);
        cellTelephone1.setBackgroundColor(new DeviceRgb(140, 221, 8));
        table.addCell(cellTelephone1);

        Cell cellCommentaire = new Cell().add(new Paragraph("Commentaire"));
        cellCommentaire.setTextAlignment(TextAlignment.CENTER);
        cellCommentaire.setFontSize(8);
        cellCommentaire.setFontColor(Color.BLACK);
        cellCommentaire.setPadding(5);
        cellCommentaire.setBackgroundColor(new DeviceRgb(140, 221, 8));
        table.addCell(cellCommentaire);

        List<Adherent> adherentsInscrit = plongee.getParticipants();

        for (Adherent adherent : adherentsInscrit) {
            Cell cellNomP = new Cell().add(new Paragraph(adherent.getNom()));
            cellNomP.setTextAlignment(TextAlignment.CENTER);
            cellNomP.setFontSize(8);
            cellNomP.setFontColor(Color.BLACK);
            cellNomP.setPadding(5);
            cellNomP.setBackgroundColor(new DeviceRgb(140, 221, 8));
            table.addCell(cellNomP);

            Cell cellPrenomP = new Cell().add(new Paragraph(adherent.getPrenom()));
            cellPrenomP.setTextAlignment(TextAlignment.CENTER);
            cellPrenomP.setFontSize(8);
            cellPrenomP.setFontColor(Color.BLACK);
            cellPrenomP.setPadding(5);
            cellPrenomP.setBackgroundColor(new DeviceRgb(140, 221, 8));
            table.addCell(cellPrenomP);

            // Ds que le plongeur est encadrant, on affiche son niveau d'encadrement
            String niveauAffiche = adherent.getPrerogative();
            // Pour les externes, le niveau est suffix par (Ext.)
            if (adherent.getActifInt() == 2) {
                niveauAffiche = niveauAffiche + " (Ext.)";
            }
            Cell cellNiveauP = new Cell().add(new Paragraph(niveauAffiche));
            cellNiveauP.setTextAlignment(TextAlignment.CENTER);
            cellNiveauP.setFontSize(8);
            cellNiveauP.setFontColor(Color.BLACK);
            cellNiveauP.setPadding(5);
            cellNiveauP.setBackgroundColor(new DeviceRgb(140, 221, 8));
            table.addCell(cellNiveauP);

            Cell cellAptitudeP;
            if (null == adherent.getAptitude()) {
                cellAptitudeP = new Cell().add(new Paragraph("  "));
            } else {
                cellAptitudeP = new Cell().add(new Paragraph(adherent.getAptitude().getText()));
            }
            cellAptitudeP.setTextAlignment(TextAlignment.CENTER);
            cellAptitudeP.setFontSize(8);
            cellAptitudeP.setFontColor(Color.BLACK);
            cellAptitudeP.setPadding(5);
            cellAptitudeP.setBackgroundColor(new DeviceRgb(140, 221, 8));
            table.addCell(cellAptitudeP);

            Cell cellTelephone1P = new Cell().add(new Paragraph(adherent.getTelephone()));
            cellTelephone1P.setTextAlignment(TextAlignment.CENTER);
            cellTelephone1P.setFontSize(8);
            cellTelephone1P.setFontColor(Color.BLACK);
            cellTelephone1P.setPadding(5);
            cellTelephone1P.setBackgroundColor(new DeviceRgb(140, 221, 8));
            table.addCell(cellTelephone1P);

            Cell cellCommentaireP = new Cell().add(new Paragraph(adherent.getCommentaire()));
            cellCommentaireP.setTextAlignment(TextAlignment.CENTER);
            cellCommentaireP.setFontSize(8);
            cellCommentaireP.setFontColor(Color.BLACK);
            cellCommentaireP.setPadding(5);
            cellCommentaireP.setBackgroundColor(new DeviceRgb(140, 221, 8));
            table.addCell(cellCommentaireP);

        }
        doc.add(table);
        doc.close();
    }

From source file:com.js.quickestquail.ui.actions.io.ExportToPDFAction.java

private void writeAll(File outputFile) throws FileNotFoundException, IOException {

    // progress dialog
    JProgressDialog dialog = new JProgressDialog(UI.get(), false);
    dialog.setMaximum(DriveManager.get().getSelected().size());
    dialog.setTitle(java.util.ResourceBundle.getBundle("i18n/i18n").getString("export.pdf"));
    dialog.setVisible(true);/*from www  .j av a 2s  . co  m*/

    // run this in a new Thread
    new Thread() {
        @Override
        public void run() {
            try {
                int nrOfMovies = 0;
                List<Entry<File, String>> entries = new ArrayList<>(
                        DriveManager.get().getSelected().entrySet());
                java.util.Collections.sort(entries, new Comparator<Entry<File, String>>() {
                    @Override
                    public int compare(Entry<File, String> o1, Entry<File, String> o2) {
                        Movie mov1 = CachedMovieProvider.get().getMovieByID(o1.getValue());
                        Movie mov2 = CachedMovieProvider.get().getMovieByID(o2.getValue());
                        return mov1.getTitle().compareTo(mov2.getTitle());
                    }
                });

                PdfWriter writer = new PdfWriter(new FileOutputStream(outputFile));
                PdfDocument pdf = new PdfDocument(writer);
                Document doc = new Document(pdf);

                for (Entry<File, String> en : entries) {
                    Movie mov = CachedMovieProvider.get().getMovieByID(en.getValue());

                    // update progress dialog
                    dialog.setText(mov.getTitle());
                    dialog.setProgress(nrOfMovies);

                    // add table
                    Table table = new Table(new float[] { 0.5f, 0.25f, 0.25f });
                    table.setWidthPercent(100);
                    table.setBorder(Border.NO_BORDER);

                    Cell cell;
                    cell = new Cell(5, 1);
                    cell.setBorder(Border.NO_BORDER);

                    try {
                        Image img = new Image(ImageDataFactory.create(new URL(mov.getPoster())));
                        cell.setNextRenderer(new ImageBackgroundCellRenderer(cell, img));
                    } catch (Exception ex) {
                    }

                    cell.setHeight(160);
                    cell.setWidth(100);

                    table.addCell(cell);

                    cell = new Cell(1, 1).add("Title").setBorder(Border.NO_BORDER);
                    table.addCell(cell);
                    cell = new Cell(1, 1).add(mov.getTitle()).setBorder(Border.NO_BORDER);
                    table.addCell(cell);

                    cell = new Cell(1, 1).add("Year").setBorder(Border.NO_BORDER);
                    table.addCell(cell);
                    cell = new Cell(1, 1).add(mov.getYear() + "").setBorder(Border.NO_BORDER);
                    table.addCell(cell);

                    cell = new Cell(1, 1).add("IMDB ID").setBorder(Border.NO_BORDER);
                    table.addCell(cell);
                    cell = new Cell(1, 1).add(mov.getImdbID()).setBorder(Border.NO_BORDER);
                    table.addCell(cell);

                    cell = new Cell(1, 1).add("IMDB Rating").setBorder(Border.NO_BORDER);
                    table.addCell(cell);
                    cell = new Cell(1, 1).add(mov.getImdbRating() + "").setBorder(Border.NO_BORDER);
                    table.addCell(cell);

                    cell = new Cell(1, 1).add("IMDB Votes").setBorder(Border.NO_BORDER);
                    table.addCell(cell);
                    cell = new Cell(1, 1).add(mov.getImdbVotes() + "").setBorder(Border.NO_BORDER);
                    table.addCell(cell);

                    doc.add(table);

                    nrOfMovies++;
                    if (nrOfMovies % 4 == 0) {
                        doc.add(new AreaBreak());
                    }

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

                }

                // close IO
                doc.close();
                pdf.close();
                writer.close();

                // close dialog
                dialog.setVisible(false);

            } catch (Exception ex) {
            }
        }
    }.start();

}

From source file:com.tcay.slalom.UI.PDF.PDF_Results.java

License:Open Source License

public void doit(String title, ArrayList<RaceRun> runs, boolean breakOnClassChange) {
    Document doc = null;/*from  w ww  .j  av a2 s  . co m*/
    Table table = null;

    try {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        // new PDF_Results().manipulatePdf(DEST);

        PdfDocument pdfDoc = new PdfDocument(new PdfWriter(DEST));
        //Document
        doc = new Document(pdfDoc);

        table = new Table(9); // # of columns
        // for (int i = 0; i < 16; i++) {
        //     table.addCell("hi");
        // }

    } catch (Exception e) {
        System.out.println(e);
        e.printStackTrace();
    }

    String lastBoatClass = null;
    for (RaceRun r : runs) {

        float totalTime;

        if (breakOnClassChange) {
            if (lastBoatClass != null) {
                if (lastBoatClass.compareTo(r.getBoat().getBoatClass()) != 0)
                    ;
                //   log.info("---");
            }
            lastBoatClass = r.getBoat().getBoatClass();
        }
        totalTime = (float) r.getTotalPenalties();
        totalTime += r.getElapsed();
    }

    try {

        ArrayList<Result> sorted = Race.getInstance().getTempResults();
        for (Result r : sorted) {
            if (true || breakOnClassChange) { //Fixme  constant true
                if (lastBoatClass != null) {
                    if (lastBoatClass.compareTo(r.getBoat().getBoatClass()) != 0)
                        ;
                    //                            output.newLine();
                }
                if (lastBoatClass == null || lastBoatClass.compareTo(r.getBoat().getBoatClass()) != 0) {
                    //                        output.write(r.getBoat().getBoatClass());
                    //                        output.newLine();
                }
                lastBoatClass = r.getBoat().getBoatClass();
            }
            String s1;

            //                Cell cell23 = new Cell(1, 6).add("a Class ???multi 1,3 and 1,4");
            //                table.addCell(cell23);
            //                table.startNewRow();

            s1 = String.format("%1$3s", r.getBoat().getRacer().getBibNumber());
            table.addCell(s1);

            String s = r.getBoat().getRacer().getShortName();
            s1 = String.format("%1$-15s", s);
            table.addCell(s1);

            s1 = r.getRun1().getResultString();
            table.addCell(s1);

            s1 = r.getRun1().getPenaltyString();
            table.addCell(s1);

            s1 = r.getRun1().getTotalTimeString();
            table.addCell(s1);

            if (r.getRun2() != null) {
                table.startNewRow();

                table.addCell(".");
                table.addCell("..");
                s1 = r.getRun2().getResultString();
                table.addCell(s1);

                s1 = r.getRun2().getPenaltyString();
                table.addCell(s1);

                s1 = r.getRun2().getTotalTimeString();
                table.addCell(s1);

            }
            //                else {
            //    table.addCell("")//;

            //}

            table.startNewRow();

            /// todo must integrate TH results before sort  - DONE VERIFY 10/11/2013
            //                output.write("   best=");
            //                s1 = r.getBestRun() != null ? r.getBestRun().formatTimeTotalOnly() : RaceRun.TIME_ONLY_FILL;
            //                output.write(s1);

            //                if (r.getBestRun().getPhotoCellRaceRun() != null) {    /// todo must integrate TH results before sort
            //                    output.write(ResultsTable.TIMINGMODE_AUTOMATIC);
            //                }
            //                output.newLine();
        }

        PdfFont f = PdfFontFactory.createFont(FontConstants.HELVETICA);
        Cell cell = new Cell(1, 3);

        cell.add(new Paragraph("Class K1 ... or whateever")).setFont(f).setFontSize(13)
                .setFontColor(DeviceGray.WHITE).setBackgroundColor(DeviceGray.BLACK);
        //  .setTextAlignment(TextAlignment.CENTER);

        table.addHeaderCell(cell);

        /*            for (int i = 0; i < 2; i++) {
        Cell[] headerFooter = new Cell[] {
                new Cell().setBackgroundColor(new DeviceGray(0.75f)).add("#"),
                new Cell().setBackgroundColor(new DeviceGray(0.75f)).add("Key"),
                new Cell().setBackgroundColor(new DeviceGray(0.75f)).add("Value")
        };
        for (Cell hfCell : headerFooter) {
            if (i == 0) {
                table.addHeaderCell(hfCell);
            } else {
                table.addFooterCell(hfCell);
            }
        }
                    }
                    for (int counter = 1; counter < 20; counter++) {
        table.addCell(new Cell().setTextAlignment(TextAlignment.CENTER).add(String.valueOf(counter)));
        table.addCell(new Cell().setTextAlignment(TextAlignment.CENTER).add("key " + counter));
        table.addCell(new Cell().setTextAlignment(TextAlignment.CENTER).add("value " + counter));
                    }
                
        */

        doc.add(table);

        doc.close();

    } catch (Exception e) {
        System.out.println(e);
        System.out.println(e.getStackTrace());
        e.printStackTrace();

        //           log.write(e);
    } finally {
        try {
            //                output.close();
        } catch (Exception ex) {
            System.out.println(ex);
            System.out.println(ex.getStackTrace());

            ex.printStackTrace();

        }
    }

}