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

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

Introduction

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

Prototype

public Text(String text) 

Source Link

Document

Constructs a Text with its role initialized.

Usage

From source file:cl.a2r.wsmicampov2.dao.TrasladoDAO.java

public static void addPageToGuia(Traslado traslado, List<String> listDiios, Document document,
        Integer cantAnimales) {/*  www.  j  a  va2 s  .c  o m*/

    try {

        Integer identificadorTraslado = traslado.getId();
        String fundoOrigen = traslado.getFundoOrigen();
        String fundoDestino = traslado.getFundoDestino();
        Date fecha = traslado.getFecha();
        String nombreChofer = traslado.getNombreChofer();
        String rutChofer = traslado.getRutChofer();
        String patenteCamion = traslado.getPatenteCamion();
        String patenteAcoplado = traslado.getAcopladoPatente();
        String nombreTransportista = traslado.getNombreTransportista();
        String rutTransportista = traslado.getRutTransportista();

        String imagePath = "/usr/share/MiCampoGuiasUpload/A2RLogo.png";
        //        String imagePath="Z:\\Chilterra\\MiCampoGuias\\A2RLogo.png";

        DateFormat df = new SimpleDateFormat("dd-MM-yyyy hh_mm_ss");
        DateFormat df2 = new SimpleDateFormat("dd-MM-yyyy");
        Date today = Calendar.getInstance().getTime();
        String reportDate = df.format(today);
        String reportDate2 = df2.format(today);

        PdfFont bold = PdfFontFactory.createFont(FontConstants.HELVETICA_BOLD);

        Text fechaText = new Text("Fecha: " + reportDate2).setTextAlignment(TextAlignment.RIGHT);
        Paragraph paragraphFecha = new Paragraph().add(fechaText);
        paragraphFecha.setTextAlignment(TextAlignment.RIGHT);
        document.add(paragraphFecha);

        Text title = new Text("TRASLADO INTERNO DE ANIMALES No. " + identificadorTraslado).setFont(bold);
        title.setFontSize(12);

        Image a2R = new Image(ImageDataFactory.create(imagePath));
        Paragraph p = new Paragraph("").add(a2R).add(title);

        document.add(p);

        //Datos del traslado
        Table table = new Table(2);

        table.addCell(CellHelper.getCell("Fundo origen: ", fundoOrigen, TextAlignment.LEFT));
        table.addCell(CellHelper.getCell("Fundo destino: ", fundoDestino, TextAlignment.LEFT));

        table.addCell(CellHelper.getCell("Nombre Chofer: ", nombreChofer, TextAlignment.LEFT));
        table.addCell(CellHelper.getCell("Rut Chofer: ", nombreChofer, TextAlignment.LEFT));

        table.addCell(CellHelper.getCell("Patente camin: ", patenteCamion, TextAlignment.LEFT));
        table.addCell(CellHelper.getCell("Patente acoplado: ", patenteAcoplado, TextAlignment.LEFT));

        table.addCell(CellHelper.getCell("Nombre transportista: ", nombreTransportista, TextAlignment.LEFT));
        table.addCell(CellHelper.getCell("Rut transportista: ", rutTransportista, TextAlignment.LEFT));

        document.add(table);

        Paragraph totalAnimales = CellHelper.getBoldParagraph("Cantidad total de animales: ",
                cantAnimales.toString());

        document.add(totalAnimales);

        //Observaciones
        Paragraph observaciones = new Paragraph("Observaciones: ").setBold();
        document.add(observaciones);

        Table observTable = new Table(1);
        observTable.addCell(CellHelper.getCellObservaciones("", TextAlignment.LEFT));
        document.add(observTable);

        Paragraph space1 = new Paragraph("");
        document.add(space1);

        Paragraph space2 = new Paragraph("");
        document.add(space2);

        Paragraph space3 = new Paragraph("");
        document.add(space3);

        Paragraph space4 = new Paragraph("");
        document.add(space4);

    } catch (Exception ex) {

    }

}

From source file:cl.a2r.wsmicampov2.dao.TrasladoDAO.java

public static void addDiiosPage(Document document, List<String> listDiios) {

    try {//from   w  w w .  j a va 2  s  . co m

        Integer cantAnimales = listDiios.size();
        Integer diff = 0;

        if (listDiios.size() < 6) {
            diff = 6 - cantAnimales;
        } else {

            if (cantAnimales % 6 != 0) {

                Integer cociente = cantAnimales / 6;
                diff = ((cociente + 1) * 6) - cantAnimales;
            }

        }

        for (int i = 0; i < diff; i++) {
            listDiios.add(" ");
        }

        PdfFont bold = PdfFontFactory.createFont(FontConstants.HELVETICA_BOLD);
        Text subTitle = new Text("Diios: ").setFont(bold);
        Paragraph subtitleParagraph = new Paragraph().add(subTitle);

        document.add(subtitleParagraph);
        Table tableDiios = new Table(6);
        for (int i = 0; i < listDiios.size(); i++) {

            tableDiios.addCell(CellHelper.getCellDiios(listDiios.get(i), TextAlignment.LEFT));
        }

        document.add(tableDiios);

    } catch (Exception ex) {

    }

}

From source file:cl.a2r.wsmicampov2.dao.TrasladoDAO.java

public static void copiaPara(String copia, Document document) {

    Text copy = new Text("Copia para " + copia).setTextAlignment(TextAlignment.CENTER);
    Paragraph paragraphCopy = new Paragraph().add(copy);
    paragraphCopy.setTextAlignment(TextAlignment.CENTER);
    document.add(paragraphCopy);/*from   w  w w.ja v  a2  s  .  c  o  m*/

}

From source file:cl.a2r.wsmicampov2.pdf.CellHelper.java

public static Cell getCell(String text1, String text2, TextAlignment alignment) {

    try {// w w w. j ava  2s .  c om
        PdfFont bold = PdfFontFactory.createFont(FontConstants.HELVETICA_BOLD);
        Text tx1 = new Text(text1).setFont(bold);

        Text tx2 = new Text(text2);
        Paragraph p = new Paragraph().add(tx1).add(tx2);

        Cell cell = new Cell().add(p);

        cell.setPadding(0);
        cell.setTextAlignment(alignment);
        cell.setBorder(Border.NO_BORDER);
        return cell;
    } catch (Exception ex) {

    }
    return null;

}

From source file:cl.a2r.wsmicampov2.pdf.CellHelper.java

public static Paragraph getBoldParagraph(String text1, String text2) {
    try {/* www  .  ja  v a 2  s  .c  o  m*/

        PdfFont bold = PdfFontFactory.createFont(FontConstants.HELVETICA_BOLD);
        Text tx1 = new Text(text1).setFont(bold);

        Text tx2 = new Text(text2);
        Paragraph p = new Paragraph().add(tx1).add(tx2);
        return p;

    } catch (Exception ex) {

    }
    return new Paragraph();
}

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

private Table createEntete(FicheSecurite fs, int numeroPage, int nbPage) throws java.io.IOException {
        float[] columnWidths = { 20, 27, 23, 23, 6 };
        // table : premiere table pour les parametres de la plonge
        Table table = new Table(columnWidths);
        table.setMargins(0, 0, 0, 0);/*from  w w  w . j  av  a 2s . c om*/
        table.setWidthPercent(100);
        // entete style pour les entetes
        Style entete = new Style();
        PdfFont fontEntete = PdfFontFactory.createFont(FontConstants.TIMES_ROMAN);
        entete.setFont(fontEntete).setFontSize(12);
        entete.setFontColor(Color.BLACK);
        // style pour les libells
        Style libelle = new Style();
        PdfFont fontLibelle = PdfFontFactory.createFont(FontConstants.TIMES_ROMAN);
        libelle.setFont(fontLibelle).setFontSize(12);
        libelle.setFontColor(Color.RED);

        Paragraph entete1 = new Paragraph();
        entete1.add(new Text("DATE\n").addStyle(entete));
        entete1.add(new Text("DIRECTEUR DE PLONGEE\n").addStyle(entete));
        entete1.add(new Text("PILOTE DU BATEAU\n").addStyle(entete));
        entete1.add(new Text("LIEU DE PLONGEE\n").addStyle(entete));
        entete1.add(new Text("METEO\n").addStyle(entete));

        Paragraph libelle1 = new Paragraph();
        libelle1.add(new Text(": " + ResaUtil.getDateString(fs.getDatePlongee()) + "\n").addStyle(libelle));
        libelle1.add(new Text(": " + fs.getNomDP() + "\n").addStyle(libelle));
        libelle1.add(new Text(": " + fs.getNomPilote() + "\n").addStyle(libelle));
        libelle1.add(new Text(": " + fs.getSite() + "\n").addStyle(libelle));
        libelle1.add(new Text(": " + fs.getMeteo() + "\n").addStyle(libelle));

        Cell cellEntete1 = new Cell();
        cellEntete1.add(entete1);
        cellEntete1.setBorderRight(Border.NO_BORDER);
        cellEntete1.setHorizontalAlignment(HorizontalAlignment.LEFT);
        table.addCell(cellEntete1);

        Cell cellLibelle1 = new Cell();
        cellLibelle1.add(libelle1);
        cellLibelle1.setBorderLeft(Border.NO_BORDER);
        cellLibelle1.setTextAlignment(TextAlignment.LEFT);
        table.addCell(cellLibelle1);

        Paragraph titre = new Paragraph();
        titre.add(new Text("ASPTT MARSEILLE\n").addStyle(entete));
        titre.add(new Text("PLONGEE\n").addStyle(entete));
        titre.add(new Text("---\n").addStyle(entete));
        titre.add(new Text("Fiche de Scurit\n").addStyle(entete));

        Cell cellTitre = new Cell();
        cellTitre.add(titre);
        cellTitre.setTextAlignment(TextAlignment.CENTER);
        cellTitre.setVerticalAlignment(VerticalAlignment.MIDDLE);
        table.addCell(cellTitre);

        Paragraph entete2 = new Paragraph();
        entete2.add(new Text("PLONGEE NUMERO\n").addStyle(entete));
        entete2.add(new Text("NOMBRE DE PLONGEURS\n").addStyle(entete));
        entete2.add(new Text("HEURE DE DEPART\n").addStyle(entete));
        entete2.add(new Text("HEURES BATEAU\n").addStyle(entete));
        entete2.add(new Text("Page \n").addStyle(entete));

        Paragraph libelle2 = new Paragraph();
        libelle2.add(new Text(": " + fs.getNumeroPlongee() + "\n").addStyle(libelle));
        libelle2.add(new Text(": " + fs.getNbPlongeurs() + "\n").addStyle(libelle));
        libelle2.add(new Text(": " + fs.getHhDepart() + ":" + fs.getMnDepart() + "\n").addStyle(libelle));
        libelle2.add(new Text(": " + fs.getNbHeuresBateau() + "\n").addStyle(libelle));
        libelle2.add(new Text(": " + numeroPage + " / " + nbPage + "\n").addStyle(libelle));

        Cell cellEntete2 = new Cell();
        cellEntete2.add(entete2);
        cellEntete2.setBorderRight(Border.NO_BORDER);
        cellEntete2.setHorizontalAlignment(HorizontalAlignment.RIGHT);
        table.addCell(cellEntete2);

        Cell cellLibelle2 = new Cell();
        cellLibelle2.add(libelle2);
        cellLibelle2.setBorderLeft(Border.NO_BORDER);
        cellLibelle2.setTextAlignment(TextAlignment.LEFT);
        table.addCell(cellLibelle2);

        return table;
    }

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

public void createPdf(String dest, FicheSecurite fs)
            throws IOException, FileNotFoundException, java.io.IOException {
        //Initialize PDF writer
        PdfWriter writer = new PdfWriter(dest);

        //Initialize PDF document
        PdfDocument pdf = new PdfDocument(writer);

        // Initialize document
        Document document = new Document(pdf);
        //Add paragraph to the document
        document.add(new Paragraph(fs.getSite()));
        // Add content
        Text title1 = new Text("The Strange Case of ").setFontColor(Color.BLUE);
        Text title2 = new Text("Dr. Jekyll SIIMMOONN").setStrokeColor(Color.GREEN)
                .setTextRenderingMode(PdfCanvasConstants.TextRenderingMode.FILL_STROKE);
        Text title3 = new Text(" and ");
        Text title4 = new Text("Mr. Hyde").setStrokeColor(Color.RED).setStrokeWidth(0.5f)
                .setTextRenderingMode(PdfCanvasConstants.TextRenderingMode.STROKE);
        Paragraph p = new Paragraph().setFontSize(24).add(title1).add(title2).add(title3).add(title4);
        document.add(p);// w  ww. ja  v a 2 s . co m

        Style normal = new Style();
        PdfFont font = PdfFontFactory.createFont(FontConstants.TIMES_ROMAN);
        normal.setFont(font).setFontSize(14);
        Style code = new Style();
        PdfFont monospace = PdfFontFactory.createFont(FontConstants.COURIER);
        code.setFont(monospace).setFontColor(Color.RED).setBackgroundColor(Color.LIGHT_GRAY);
        Paragraph p2 = new Paragraph();
        p2.add(new Text("The Strange Case of ").addStyle(normal));
        p2.add(new Text("Dr. Jekyll").addStyle(code));
        p2.add(new Text(" and ").addStyle(normal));
        p2.add(new Text("Mr. Hyde").addStyle(code));
        p2.add(new Text(".").addStyle(normal));
        document.add(p2);

        //Close document
        document.close();
        //        PageSize ps = PageSize.A4.rotate();
        //        PdfPage page = pdf.addNewPage(ps);
        //        PdfCanvas canvas = new PdfCanvas(page);
        //        canvas.concatMatrix(1, 0, 0, 1, ps.getWidth() / 2, ps.getHeight() / 2);
        ////Draw X axis
        //        canvas.moveTo(-(ps.getWidth() / 2 - 15), 0)
        //                .lineTo(ps.getWidth() / 2 - 15, 0)
        //                .stroke();
        ////Draw X axis arrow
        //        canvas.setLineJoinStyle(PdfCanvasConstants.LineJoinStyle.ROUND)
        //                .moveTo(ps.getWidth() / 2 - 25, -10)
        //                .lineTo(ps.getWidth() / 2 - 15, 0)
        //                .lineTo(ps.getWidth() / 2 - 25, 10).stroke()
        //                .setLineJoinStyle(PdfCanvasConstants.LineJoinStyle.MITER);
        ////Draw Y axis
        //        canvas.moveTo(0, -(ps.getHeight() / 2 - 15))
        //                .lineTo(0, ps.getHeight() / 2 - 15)
        //                .stroke();
        ////Draw Y axis arrow
        //        canvas.saveState()
        //                .setLineJoinStyle(PdfCanvasConstants.LineJoinStyle.ROUND)
        //                .moveTo(-10, ps.getHeight() / 2 - 25)
        //                .lineTo(0, ps.getHeight() / 2 - 15)
        //                .lineTo(10, ps.getHeight() / 2 - 25).stroke()
        //                .restoreState();
        ////Draw X serif
        //        for (int i = -((int) ps.getWidth() / 2 - 61);
        //                i < ((int) ps.getWidth() / 2 - 60); i += 40) {
        //            canvas.moveTo(i, 5).lineTo(i, -5);
        //        }
        ////Draw Y serif
        //        for (int j = -((int) ps.getHeight() / 2 - 57);
        //                j < ((int) ps.getHeight() / 2 - 56); j += 40) {
        //            canvas.moveTo(5, j).lineTo(-5, j);
        //        }
        //        canvas.stroke();
        ////        pdf.close();
        ////        PdfPage page = pdf.addNewPage();
        ////        Rectangle rectangle = new Rectangle(x, y, 100, 100);
        ////        Canvas canvas = new Canvas(pdfCanvas, pdf, rectangle);
        //        float llx = 0;
        //        float lly = 0;
        //        float urx = 100;
        //        float ury = 100;
        //        for (Palanque palanque : fs.getPalanques()) {
        //            llx=llx+5;
        //            lly=lly+70;
        //            Rectangle rectangle = new Rectangle(llx, lly, urx-llx, ury-lly);
        ////            PdfCanvas canvas = new PdfCanvas(page);
        //            canvas = new PdfCanvas(page);
        ////            PdfCanvas canvas = new PdfCanvas(pdf.addNewPage());
        ////            pdfCanvas.rectangle(rectangle);
        //            canvas.setStrokeColor(Color.RED).setLineWidth(0.5f).rectangle(rectangle).stroke();
        ////            canvas = new Canvas(pdfCanvas, pdf, rectangle);
        ////            pdfCanvas.stroke();
        //            PdfFont fontRoman = PdfFontFactory.createFont(FontConstants.TIMES_ROMAN);
        //            PdfFont bold = PdfFontFactory.createFont(FontConstants.TIMES_BOLD);
        //            Text title = new Text("GUIDE palanque:"+palanque.getNomCompletGuide()).setFont(bold);
        //            Text author = new Text("PLONGEUR 1 palanque:"+palanque.getNomCompletPlongeur1()).setFont(fontRoman);
        //            Paragraph p3 = new Paragraph().add(title).add(" by ").add(author);
        //            new Canvas(canvas,pdf,rectangle).add(p3);
        ////            canvas.add(p3);
        //        }
        //Close document
        pdf.close();

    }

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 ww  w .  j  a  v  a 2s  .  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:org.nih.nci.App.java

protected void generatePdf(String dest, NCIDosePdfObject jObject) throws Exception {

    PdfWriter writer = new PdfWriter(dest, new WriterProperties().addXmpMetadata());
    PdfDocument pdfDoc = new PdfDocument(writer);
    Document document = new Document(pdfDoc, PageSize.LETTER, false);

    pdfDoc.setTagged();/*  w  w  w . j a v  a  2s . c om*/
    pdfDoc.getCatalog().setViewerPreferences(new PdfViewerPreferences().setDisplayDocTitle(true));
    pdfDoc.getCatalog().setLang(new PdfString("en-US"));
    pdfDoc.getCatalog().setViewerPreferences(new PdfViewerPreferences().setDisplayDocTitle(true));
    PdfDocumentInfo info = pdfDoc.getDocumentInfo();
    info.setTitle("Software Transfer Agreement");

    Style headerStyle = new Style();
    PdfFont headerFont = PdfFontFactory.createFont(FontConstants.HELVETICA);
    headerStyle.setFont(headerFont).setFontSize(10);

    HeaderEventHandler handler = new HeaderEventHandler();
    pdfDoc.addEventHandler(PdfDocumentEvent.END_PAGE, handler);
    handler.setHeader("NCI Reference # ___________________");

    Style titleStyle = new Style();
    PdfFont titleFont = PdfFontFactory.createFont(FontConstants.TIMES_BOLD, true);
    titleStyle.setFont(titleFont).setFontSize(14);

    Style normalStyle = new Style();
    PdfFont normalFont = PdfFontFactory.createFont(FontConstants.TIMES_ROMAN, true);
    normalStyle.setFont(normalFont).setFontSize(12);

    Style italicStyle = new Style();
    PdfFont italicFont = PdfFontFactory.createFont(FontConstants.TIMES_ITALIC, true);
    italicStyle.setFont(italicFont).setFontSize(12);

    InputStream istream = getClass().getResourceAsStream("/FreeSerif.ttf");
    byte[] bytes = IOUtils.toByteArray(istream);
    PdfFont symbol = PdfFontFactory.createFont(bytes, PdfEncodings.IDENTITY_H, true);

    Text checkbox = new Text("\u2611");//
    checkbox.setFont(symbol);
    checkbox.setFontSize(12);

    Paragraph p = new Paragraph();
    p.setMarginTop(20);
    p.setTextAlignment(TextAlignment.CENTER);
    Text text = new Text("SOFTWARE TRANSFER AGREEMENT").addStyle(titleStyle);
    p.add(text);
    document.add(p);

    p = new Paragraph();
    p.setMarginLeft(56f);
    text = new Text("Provider: National Cancer Institute (NCI)").addStyle(normalStyle);
    p.add(text);
    document.add(p);

    p = new Paragraph();
    p.setMarginLeft(56f);
    text = new Text("Recipient Institution: ").addStyle(normalStyle);
    p.add(text);
    text = new Text(jObject.getInstitution()).addStyle(italicStyle).setUnderline();
    p.add(text);
    document.add(p);

    p = new Paragraph();
    p.setMarginLeft(28f);
    text = new Text("WHEREAS, Provider has certain proprietary software and associated material described "
            + "below (hereinafter, collectively referred to as Software) ");
    text.addStyle(normalStyle);
    p.add(text).add(new Text("[Describe all items being "
            + "transferred such as; software, executable code, source code, documentation, data and all "
            + "other associated materials]").addStyle(italicStyle));
    p.add(new Text(":").addStyle(normalStyle));
    document.add(p);

    for (String str : jObject.getSoftwareText()) {
        p = new Paragraph();
        p.setMarginLeft(56f);
        text = new Text(str);
        text.addStyle(normalStyle).setBold();
        p.add(checkbox).add(text);
        document.add(p);
    }

    p = new Paragraph();
    p.setMarginLeft(28f);
    text = new Text("Provider agrees to transfer such Software to Recipient Investigator, to be used solely in "
            + "connection with the following research activity and for the following reasons (hereinafter "
            + "Project)");
    text.addStyle(normalStyle);
    p.add(text).add(new Text("[Describe with specificity the scope of use of Software under this agreement]")
            .addStyle(italicStyle));
    p.add(new Text(":").addStyle(normalStyle));
    document.add(p);

    p = new Paragraph();
    p.setMarginLeft(56f);
    text = new Text(jObject.getPurpose());
    text.addStyle(italicStyle).setUnderline();
    p.add(text);
    document.add(p);

    p = new Paragraph();
    p.setMarginLeft(28f);
    text = new Text("NOW, THEREFORE, in consideration of the premises and mutual covenants contained "
            + "herein, the Provider and Recipient agree as follows:");
    text.addStyle(normalStyle);
    p.add(text);
    document.add(p);

    List mainList = new List();
    mainList.setListSymbol("");

    List numberedList = new List(ListNumberingType.DECIMAL);
    numberedList.setMarginLeft(56f);
    numberedList.addStyle(normalStyle);

    numberedList.add("SOFTWARE SHALL NOT BE USED FOR TREATING OR DIAGNOSING " + "HUMAN SUBJECTS.");
    numberedList.add("Recipient will not license or sell or use Software for commercial purposes or "
            + "applications. Recipient Investigator shall retain control over Software and further "
            + "will not transfer the Software to individuals not under Recipient Investigators "
            + "direct supervision without the advance written approval of Provider. Recipient "
            + "agrees to comply with all regulations applicable to the Project and the use of the "
            + "Software.");
    numberedList.add("Recipient agrees not to copy Software, in whole or in part, except as required for "
            + "use by Recipient Investigator for the conduct of the Project. Recipient shall not "
            + "modify, extend, decompile, make derivatives of or reverse engineer the Software "
            + "without written permission from Provider.");
    numberedList.add("Information deemed confidential under this Agreement (Confidential Information?) "
            + "shall be clearly marked CONFIDENTIAL.? Any information that is orally "
            + "disclosed must be reduced to writing and marked CONFIDENTIAL? by the "
            + "provider of the information within thirty (30) days of such disclosure. To the extent "
            + "permitted by applicable law, the Recipient agrees to employ all reasonable efforts to "
            + "safeguard Providers Confidential Information to ensure that no unauthorized "
            + "person shall have access thereto and that no unauthorized copy, publication, "
            + "disclosure or distribution, in whole or in part, in any form shall be made.");
    numberedList.add("In all oral presentations or written publications concerning the Project, Recipient "
            + "will acknowledge Providers contribution of Software unless requested otherwise. "
            + "Recipient may publish or otherwise publicly disclose the results of the Project, but "
            + "if Provider has given Confidential Information to Recipient, such public disclosure "
            + "may be made only after Provider has had 30 days to review the proposed disclosure, "
            + "except when a shortened time period under court order or the Freedom of "
            + "Information Act pertains.");

    numberedList.add("The obligations of Recipient under Paragraph 4 above shall not extend to any part "
            + "of the Confidential Information:");

    ListItem item1 = new ListItem();
    item1.add(numberedList);
    mainList.add(item1);

    List subList = new List(ListNumberingType.ENGLISH_LOWER);
    subList.addStyle(normalStyle);
    subList.setMarginLeft(84f);

    subList.add("that can be demonstrated to have been publicly known at the time of " + "disclosure; or");
    subList.add("that can be demonstrated to have been properly in the Recipients "
            + "possession or that can be demonstrated to have been readily available to the "
            + "Recipient from another proper source prior to the disclosure; or");
    subList.add("that becomes part of the public domain or publicly known by publication or "
            + "otherwise, not due to any unauthorized act by the Recipient or its " + "subsidiaries; or");
    subList.add("that can be demonstrated as independently developed or acquired by the "
            + "Recipient without reference to or reliance upon such information; or");
    subList.add("that is required to be disclosed by law, provided that the Recipient takes "
            + "reasonable and lawful actions to avoid and/or minimize such disclosure.");

    ListItem item2 = new ListItem();
    item2.add(subList);
    mainList.add(item2);

    numberedList = new List(ListNumberingType.DECIMAL);
    numberedList.setMarginLeft(56f);
    numberedList.addStyle(normalStyle);
    numberedList.setItemStartIndex(7);

    numberedList.add("The Recipients obligations under Paragraphs 4 and 5 shall extend for a period of "
            + "three (3) years from the date of disclosure.");

    numberedList.add("Title in the Software shall remain with the Provider. It is understood that nothing "
            + "herein shall be deemed to constitute, by implication or otherwise, the grant to either "
            + "Party by the other of any license or other rights under any patent, patent application "
            + "or other intellectual property right or interest. Provider reserves the right to "
            + "distribute Software to others and to use it for Providers own purposes.");

    numberedList.add("When the Project is completed or this Agreement is terminated, whichever occurs "
            + "first, Recipient will destroy all copies of Software and Providers Confidential "
            + "Information unless directed otherwise by Provider in writing.");

    numberedList.add("This Agreement may be terminated by either Recipient or Provider by providing 30 "
            + "days advance notice.");

    numberedList.add("The Provider and Recipient each shall retain title to any patent or other intellectual "
            + "property of their respective employees developed or created in the course of the "
            + "Project defined in this Agreement. Neither Provider nor Recipient promise rights in "
            + "advance for inventions developed under this Agreement.");

    numberedList.add("No indemnification for any loss, claim, damage, or liability is intended or provided "
            + "by any party under this Agreement. Each party shall be liable for any loss, claim, "
            + "damage, or liability that said party incurs as a result of said partys activities under "
            + "this Agreement, except that the NIH, as an agency of the United States, assumes "
            + "liability only to the extent as provided under the United States Federal Tort Claims "
            + "Act (28 U.S.C. Chapter 171).");

    numberedList.add("Software is supplied AS IS, without any accompanying services or improvements\n"
            + "from Provider. SOFTWARE IS SUPPLIED TO RECIPIENT WITH NO\n"
            + "WARRANTIES, EXPRESS OR IMPLIED, INCLUDING ANY WARRANTY OF\n"
            + "MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Provider\n"
            + "makes no representations that the use of Software will not infringe any patent or\n"
            + "proprietary rights of third parties.");

    ListItem item3 = new ListItem();
    item3.add(numberedList);
    mainList.add(item3);

    document.add(mainList);

    p = new Paragraph();
    p.setMarginTop(20);
    p.setTextAlignment(TextAlignment.CENTER);
    text = new Text("Signatures Begin on Next Page").addStyle(titleStyle).setFontSize(12);
    p.add(text);
    document.add(p);
    document.add(new AreaBreak(AreaBreakType.NEXT_PAGE));

    p = new Paragraph();
    p.setMarginTop(20f);
    p.setMarginLeft(28f);
    text = new Text("For Recipient:").addStyle(titleStyle);
    p.add(text);
    document.add(p);

    p = new Paragraph();
    p.setMarginLeft(28f);
    text = new Text("Authorized Official for Recipient:").addStyle(italicStyle);
    p.add(text);
    document.add(p);

    p = new Paragraph();
    p.setMarginTop(10);
    p.setMarginLeft(28f);
    text = new Text("Name: _________________________________________  Title: _____________________\n")
            .addStyle(normalStyle);
    p.add(text);
    text = new Text("Signature: ______________________________________  Date: _____________________")
            .addStyle(normalStyle);
    p.add(text);
    document.add(p);

    p = new Paragraph();
    p.setMarginLeft(28f);
    p.setMarginTop(10);
    text = new Text("Read and Understood by Recipient Investigator:").addStyle(italicStyle);
    p.add(text);
    document.add(p);

    p = new Paragraph();
    p.setMarginLeft(28f);
    p.setMarginTop(10);
    p.add(new Text("Name: ").addStyle(normalStyle)).add(new Text(jObject.getFirst()).addStyle(italicStyle))
            .add(new Text(" ")).add(new Text(jObject.getLast()).addStyle(italicStyle)).add(new Tab())
            .add(new Text("Title: ").addStyle(normalStyle))
            .add(new Text(jObject.getTitle()).addStyle(italicStyle)).add(new Text("\n"));
    text = new Text("Signature: ____________________________________  Date: _____________________")
            .addStyle(normalStyle);
    p.add(text);
    document.add(p);

    p = new Paragraph();
    p.setMarginLeft(28f);
    p.setMarginTop(10);
    text = new Text("Recipients Mailing Address for Legal Notices:").addStyle(normalStyle);
    p.add(text);
    document.add(p);

    p = new Paragraph();
    p.setMarginLeft(28f);
    p.setMarginTop(10);
    text = new Text(jObject.getAddress()).addStyle(italicStyle);
    p.add(text);
    document.add(p);

    p = new Paragraph();
    p.setMarginLeft(28f);
    p.setMarginTop(10);
    p.add(new Text("Email: ").addStyle(normalStyle)).add(new Text(jObject.getEmail()).addStyle(italicStyle))
            .add(new Tab()).add(new Text("Phone: ").addStyle(normalStyle))
            .add(new Text(jObject.getPhone()).addStyle(italicStyle));

    document.add(p);

    p = new Paragraph();
    p.setMarginLeft(28f);
    p.setMarginTop(20);
    text = new Text("For Provider:").addStyle(titleStyle);
    p.add(text);
    document.add(p);

    p = new Paragraph();
    p.setMarginLeft(28f);
    text = new Text("Authorized Official for Provider:").addStyle(italicStyle);
    p.add(text);
    document.add(p);

    p = new Paragraph();
    p.setMarginLeft(28f);
    text = new Text("Name: _________________________________________  Title: _____________________\n")
            .addStyle(normalStyle);
    p.add(text);
    text = new Text("Signature: ______________________________________  Date: _____________________")
            .addStyle(normalStyle);
    p.add(text);
    document.add(p);

    p = new Paragraph();
    p.setMarginLeft(28f);
    p.setMarginTop(10);
    text = new Text("Read and Understood by Providers Investigator:").addStyle(italicStyle);
    p.add(text);
    document.add(p);

    p = new Paragraph();
    p.setMarginLeft(28f);
    p.setMarginTop(10);
    text = new Text("Signature: ______________________________________  Date: _____________________\n"
            + "Choonsik Lee, PhD\n" + "Senior Investigator\n" + "Radiation Epidemiology Branch\n"
            + "Division of Cancer Epidemiology & Genetics, NCI, NIH").addStyle(normalStyle);
    p.add(text);
    document.add(p);

    p = new Paragraph();
    p.setMarginLeft(28f);
    text = new Text("Providers Mailing Address for Legal Notices:").addStyle(normalStyle);
    p.add(text);
    document.add(p);

    p = new Paragraph();
    p.setMarginLeft(56f);
    text = new Text(
            "National Institutes of Health\n" + "National Cancer Institute\n" + "Technology Transfer Center\n"
                    + "9609 Medical Center Dr. Rm 1E530, MSC 9702 Bethesda, MD 20892-9702\n"
                    + "Phone: 240-276-5530 Fax: 240-276-5504").addStyle(normalStyle);
    p.add(text);
    document.add(p);

    addPageNumbers(pdfDoc);
    document.close();

}

From source file:Utils.PdfUtil.java

private void addContent(Document document) {
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
    Paragraph paragraphCustomer = new Paragraph();
    paragraphCustomer.add(new Text("Khch hng ").setFont(mCommonFont));
    com.itextpdf.layout.element.List listCustomer = new com.itextpdf.layout.element.List().setSymbolIndent(12)
            .setListSymbol("\u2022").setFont(mCommonFont);
    listCustomer.add(new ListItem("H? tn: " + mCustomer.getFullname()))
            .add(new ListItem("Chng minh nhn dn: " + mCustomer.getIdentityCode()))
            .add(new ListItem("S in thoi: " + mCustomer.getPhoneNumber()));
    listCustomer.setMarginLeft(30).setFont(mCommonFont);

    Room objRoom = (new ModelRoom()).getItemById(mRoomStatus.getIdRoom());
    Paragraph paragraphRoom = new Paragraph();
    paragraphRoom.add(new Text("Phng").setFont(mCommonFont));
    com.itextpdf.layout.element.List listRoom = new com.itextpdf.layout.element.List().setSymbolIndent(12)
            .setListSymbol("\u2022").setFont(mCommonFont);
    listRoom.add(new ListItem("Tn phng: " + objRoom.getRoomName()))
            .add(new ListItem("Loi phng: " + Constant.ROOM_TYPE_NAME[objRoom.getType()]))
            .add(new ListItem("Gi: " + CommonFunction.convertDoubleToMoney(objRoom.getPrice()) + ""))
            .add(new ListItem("Ngy n: " + sdf.format(mRoomStatus.getDateCome())))
            .add(new ListItem("Ngy i: " + sdf.format(mRoomStatus.getDateLeave())));
    listRoom.setMarginLeft(30).setFont(mCommonFont);

    Paragraph paragraphService = new Paragraph();
    paragraphService.add(new Text("Dch v").setFont(mCommonFont));
    Table table = new Table(new float[] { 10f, 7f, 5f, 5f, 7f });
    table.setWidthPercent(100).setTextAlignment(TextAlignment.CENTER)
            .setHorizontalAlignment(HorizontalAlignment.CENTER);
    String[] header = { "Tn dch v", "Gi ti?n", "S lng", "Ngy s dng" };
    for (int i = 0, k = header.length; i < k; i++) {
        Cell cellHeader = new Cell();
        cellHeader.add(header[i]);//w  ww . j a  va 2 s.  c om
        cellHeader.setNextRenderer(new RoundedCornersCellRenderer(cellHeader));
        cellHeader.setPadding(5).setBorder(Border.NO_BORDER);
        table.addHeaderCell(cellHeader);
    }
    double total = 0;
    for (CustomerService objCustomerService : mListCustomerService) {
        total += (objCustomerService.getPrice() * objCustomerService.getNumber());
        for (int i = 0; i < 4; i++) {
            Cell cell = new Cell();
            switch (i) {
            case 0:
                cell.add(objCustomerService.getServiceName());
                break;
            case 1:
                cell.add(CommonFunction.convertDoubleToMoney(objCustomerService.getPrice()) + "");
                break;
            case 2:
                cell.add(objCustomerService.getNumber() + "");
                break;
            case 3:
                cell.add(sdf.format(objCustomerService.getDateUsed()));
                break;
            }
            table.addCell(cell);
        }
    }
    Cell cellFooter = new Cell(1, 3);
    cellFooter.add("Tng ti?n: ");
    table.addCell(cellFooter);
    cellFooter = new Cell();
    cellFooter.add(CommonFunction.convertDoubleToMoney(total) + "");
    table.addCell(cellFooter);

    document.add(paragraphCustomer).add(listCustomer);
    document.add(paragraphRoom).add(listRoom);
    document.add(paragraphService).add(table);
}