Example usage for com.itextpdf.kernel.pdf PdfDocument addNewPage

List of usage examples for com.itextpdf.kernel.pdf PdfDocument addNewPage

Introduction

In this page you can find the example usage for com.itextpdf.kernel.pdf PdfDocument addNewPage.

Prototype

public PdfPage addNewPage(int index) 

Source Link

Document

Creates and inserts new page to the document.

Usage

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

public Document createPdfFS(String dest, FicheSecurite fs)
            throws IOException, FileNotFoundException, java.io.IOException {
        PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
        PageSize ps = PageSize.A4.rotate();
        //calcul du nombre de page (si + de 8 palanques => 2 pages)
        int nbPage = 1;
        if (fs.getPalanques().size() > 8) {
            nbPage = 2;/*from  ww  w  .  j a v  a2  s.co  m*/
        }
        pdfDoc.addNewPage(ps);
        Document doc = new Document(pdfDoc);
        Table entete = createEntete(fs, 1, nbPage);
        doc.add(entete);

        // style pour les plongeurs
        Style s_plongeur = new Style();
        PdfFont fontPlongeur = PdfFontFactory.createFont(FontConstants.TIMES_ROMAN);
        s_plongeur.setFont(fontPlongeur).setFontSize(10);
        s_plongeur.setFontColor(Color.BLACK);
        // Deuxieme table pour les palanques 
        Table tablePalanques = new Table(4);
        for (int i = 0; i < 8; i++) {
            createTablePlongeur(tablePalanques, fs, i, s_plongeur);
        }
        doc.add(tablePalanques);
        if (nbPage == 2) {
            Table tablePalanques2 = new Table(4);
            pdfDoc.addNewPage(ps);
            Table entete2 = createEntete(fs, 2, nbPage);
            doc.add(entete2);
            for (int i = 8; i < 16; i++) {
                createTablePlongeur(tablePalanques2, fs, i, s_plongeur);
            }
            doc.add(tablePalanques2);
        }
        doc.close();
        return doc;
    }

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);
        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);/*from  w w w .ja v a 2 s.  co  m*/
        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();
    }