Example usage for com.itextpdf.text Paragraph add

List of usage examples for com.itextpdf.text Paragraph add

Introduction

In this page you can find the example usage for com.itextpdf.text Paragraph add.

Prototype

@Override
public boolean add(Element o) 

Source Link

Document

Adds an Element to the Paragraph.

Usage

From source file:be.thomasmore.service.CreatePDFServiceImp.java

@Override
public void createPDF(List<Score> scores) {
    try {//from   w ww .  j av a  2 s.co  m
        OutputStream file = new FileOutputStream(new File("D:\\Desktop\\Scores.pdf"));

        Document document = new Document();
        PdfWriter.getInstance(document, file);

        document.open();
        document.add(new Paragraph("Scores"));
        document.add(new Paragraph(new Date().toString()));

        document.addAuthor("Projectgroep 4");
        document.addCreator("Projectgroep 4");
        document.addTitle("ScoreTracker");

        //Create Paragraph
        Paragraph paragraph = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD));

        //New line
        paragraph.add(new Paragraph(" "));
        paragraph.add("Scores");
        paragraph.add(new Paragraph(" "));
        document.add(paragraph);

        //Create a table in PDF
        PdfPTable pdftabel = new PdfPTable(4);
        PdfPCell cell1 = new PdfPCell(new Phrase("Student"));
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        pdftabel.addCell(cell1);

        cell1 = new PdfPCell(new Phrase("Vak"));
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        pdftabel.addCell(cell1);

        cell1 = new PdfPCell(new Phrase("Test"));
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        pdftabel.addCell(cell1);

        cell1 = new PdfPCell(new Phrase("Score"));
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        pdftabel.addCell(cell1);

        pdftabel.setHeaderRows(1);

        for (Score score : scores) {
            pdftabel.addCell(score.getStudent().getNaam());
            pdftabel.addCell(score.getTest().getVak().getNaam());
            pdftabel.addCell(score.getTest().getNaam());
            int resultaat = score.getScore();
            pdftabel.addCell(resultaat + " / " + score.getTest().getTotaal());
        }

        document.add(pdftabel);
        document.addCreationDate();
        document.close();
        file.close();

    } catch (Exception e) {

        e.printStackTrace();
    }
}

From source file:be.thomasmore.service.CreatePDFServiceImp.java

@Override
public void createPDFVoorStudent(ArrayList<ArrayList<Score>> puntenlijst, List<Double> gemiddeldelijst,
        Double totaalGemiddelde) {
    try {/*from  www  .  ja v  a2s . c o  m*/
        OutputStream file = new FileOutputStream(new File("D:\\Desktop\\Scores.pdf"));

        Document document = new Document();
        PdfWriter.getInstance(document, file);

        document.open();
        document.add(new Paragraph("Scores"));
        document.add(new Paragraph(puntenlijst.get(0).get(0).getStudent().getNaam()));
        document.add(new Paragraph(new Date().toString()));

        document.addAuthor("Projectgroep 4");
        document.addCreator("Projectgroep 4");
        document.addTitle("ScoreTracker");

        //Create Paragraph
        Paragraph paragraph = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD));

        //New line
        paragraph.add(new Paragraph(" "));
        paragraph.add("Scores");
        paragraph.add(new Paragraph(" "));
        document.add(paragraph);

        for (int i = 0; i < puntenlijst.size(); i++) {
            //Create a table in PDF
            PdfPTable pdftabel = new PdfPTable(2);
            //vak invullen
            paragraph = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD));
            paragraph.add(new Paragraph(puntenlijst.get(i).get(0).getTest().getVak().getNaam()));
            document.add(paragraph);

            PdfPCell cell1 = new PdfPCell(new Phrase("Test"));
            cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
            pdftabel.addCell(cell1);

            cell1 = new PdfPCell(new Phrase("Score"));
            cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
            pdftabel.addCell(cell1);

            pdftabel.setHeaderRows(1);

            for (Score score : puntenlijst.get(i)) {
                pdftabel.addCell(score.getTest().getNaam());
                int resultaat = score.getScore();
                pdftabel.addCell(resultaat + " / " + score.getTest().getTotaal());
            }

            document.add(pdftabel);

            //gemmidelde per vak invoeren
            paragraph = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD));
            paragraph.add(new Paragraph("Gemiddelde: " + gemiddeldelijst.get(i).toString()));
            document.add(paragraph);
        }
        paragraph = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD));
        paragraph.add(new Paragraph("Algemeen gemiddelde: " + totaalGemiddelde));
        document.add(paragraph);
        document.addCreationDate();
        document.close();
        file.close();

    } catch (Exception e) {

        e.printStackTrace();
    }
}

From source file:bestdeal.util.genererPdf.java

public static void main(String[] args) {
    // - Paramtres de connexion  la base de donnes
    Connection connection;//from w  w  w .ja  v a2 s.co  m
    String[][] data = new String[][] { { " ", " ", " ", " ", " " }, { " ", " ", " ", " ", " " },
            { " ", " ", " ", " ", " " }, };

    try {
        String requete = "select c.nom,c.prenom,c.email,k.nom,k.prenom,k.telephone,k.adresse,k.email,d.id_deal,d.nom_deal,v.quantite,v.prix_unitaire from client c INNER JOIN voucher v on v.id_client=c.id_client INNER JOIN deal d on v.id_deal=d.id_deal INNER JOIN vendeur k on d.id_vendeur=k.id_vendeur";
        connection = MyConnection.getInstance();
        mypdf = new Document(PageSize.A4, 50, 50, 50, 50);
        File di = new File("C:/Voucher");
        File fl[] = di.listFiles();
        try {
            OutputStream file = new FileOutputStream(new File("C:/Voucher\\Voucher.pdf"));
            PdfWriter.getInstance(mypdf, file);

            mypdf.open();
            Statement stm;

            mypdf.addAuthor("Best Deal");
            mypdf.addSubject("Voucher ");
            mypdf.add(new Paragraph("Socite BestDeal"));
            mypdf.add(new Paragraph("Adresse La Chotrana ESPRIT "));
            mypdf.add(new Paragraph("TEL : xx xxx xxx"));
            mypdf.add(new Paragraph("FAX : xx xxx xxx"));
            mypdf.add(new Paragraph(
                    "                                                                                                       "
                            + new Date().toString()));
            mypdf.add(new Paragraph("  "));
            mypdf.add(new Paragraph("                                   " + "Voucher N'01",
                    FontFactory.getFont(FontFactory.HELVETICA, 21, Font.BOLDITALIC)));
            mypdf.add(new Paragraph("  "));

            mypdf.add(new Paragraph("CLIENT :",
                    FontFactory.getFont(FontFactory.TIMES_ROMAN, 13, Font.BOLDITALIC)));
            try {
                stm = connection.createStatement();
                ResultSet rs = stm.executeQuery(requete);

                while (rs.next()) {
                    // add a country to the document as a Chunk
                    //mypdf.add(new Chunk(rs.getString("quantite")));
                    Phrase p = new Phrase("Nom:   ");
                    Phrase p2 = new Phrase(new Chunk(rs.getString("nom")));
                    Paragraph pa = new Paragraph();
                    pa.add(p);
                    pa.add(p2);
                    mypdf.add(pa);

                    Phrase p3 = new Phrase("Prenom:  ");
                    Phrase p4 = new Phrase(new Chunk(rs.getString("prenom")));
                    Paragraph pa1 = new Paragraph();
                    pa1.add(p3);
                    pa1.add(p4);
                    mypdf.add(pa1);

                    Phrase p5 = new Phrase("Adresse:  ");
                    Phrase p6 = new Phrase(new Chunk(rs.getString("adresse")));
                    Paragraph pa2 = new Paragraph();
                    pa2.add(p5);
                    pa2.add(p6);
                    mypdf.add(pa2);

                    Phrase p7 = new Phrase("Tlphone:  ");
                    Phrase p8 = new Phrase(new Chunk(rs.getString("telephone")));
                    Paragraph pa3 = new Paragraph();
                    pa3.add(p7);
                    pa3.add(p8);
                    mypdf.add(pa3);

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

                    mypdf.add(new Paragraph("Vendeur :",
                            FontFactory.getFont(FontFactory.TIMES_ROMAN, 13, Font.BOLDITALIC)));

                    Phrase p9 = new Phrase("Nom:  ");
                    Phrase p10 = new Phrase(new Chunk(rs.getString("nom")));
                    Paragraph pa4 = new Paragraph();
                    pa4.add(p9);
                    pa4.add(p10);
                    mypdf.add(pa4);

                    Phrase p11 = new Phrase("Prnom:  ");
                    Phrase p12 = new Phrase(new Chunk(rs.getString("prenom")));
                    Paragraph pa5 = new Paragraph();
                    pa5.add(p11);
                    pa5.add(p12);
                    mypdf.add(pa5);

                    Phrase p13 = new Phrase("Tlphone:  ");
                    Phrase p14 = new Phrase(new Chunk(rs.getString("telephone")));
                    Paragraph pa6 = new Paragraph();
                    pa6.add(p13);
                    pa6.add(p14);
                    mypdf.add(pa6);

                    Phrase p15 = new Phrase("Adresse:  ");
                    Phrase p16 = new Phrase(new Chunk(rs.getString("adresse")));
                    Paragraph pa7 = new Paragraph();
                    pa7.add(p15);
                    pa7.add(p16);
                    mypdf.add(pa7);

                    Phrase p17 = new Phrase("Email:  ");
                    Phrase p18 = new Phrase(new Chunk(rs.getString("email")));
                    Paragraph pa8 = new Paragraph();
                    pa8.add(p17);
                    pa8.add(p18);
                    mypdf.add(pa8);

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

                    for (int i = 0; i < rs.getRow(); i++) {
                        for (int j = 0; j < data[i].length - 1; j++) {
                            data[i][j] = rs.getString(j + 9);
                            // if (j==3)
                            //     data[i][4]= Float.parseFloat(data[i][3])*Integer.parseInt(data[i][2])+"";
                        }
                    }

                    for (int i = 0; i < rs.getRow(); i++) {
                        float s = Integer.parseInt(data[i][2].trim()) * Float.parseFloat(data[i][3].trim());
                        data[i][4] = s + "";
                    }

                    //mypdf.add(new Phrase("nom"));
                    //mypdf.add(new  Chunk(rs.getString("nom")));
                    //mypdf.add( new Paragraph("nom:", new Chunk(rs.getString("nom"))));
                    //mypdf.add(new Chunk(" "));
                    //Chunk id = new Chunk(rs.getString("id"));
                    // with a background color
                    //id.setBackground(BaseColor.BLACK, 1f, 0.5f, 1f, 1.5f);
                    // and a text rise
                    //id.setTextRise(6);
                    //  mypdf.add(id);
                    mypdf.add(Chunk.NEWLINE);
                }

            } catch (SQLException ex) {
                Logger.getLogger(genererPdf.class.getName()).log(Level.SEVERE, null, ex);
            }
            // mypdf.add(new Paragraph("Nom "));
            //  mypdf.add(new Paragraph("Prenom "));
            // mypdf.add(new Paragraph("Adresse "));
            //mypdf.add(new Paragraph("Tlphone "));

            // mypdf.add(new Paragraph("Nom "));
            // mypdf.add(new Paragraph("Nom de la socit "));
            //  mypdf.add(new Paragraph("Adresse "));
            // mypdf.add(new Paragraph("Tlphone "));
            // mypdf.add(new Paragraph("  "));

            String[] headers = new String[] { "  Id_deal", "   Nom Deal", "   Quantit", "    Prix unitaire",
                    "   Prix total" };
            PdfPTable table = new PdfPTable(headers.length);
            for (int i = 0; i < headers.length; i++) {
                String header = headers[i];
                PdfPCell cell = new PdfPCell();
                cell.setGrayFill(0.9f);
                cell.setPhrase(new Phrase(header.toUpperCase()));
                table.addCell(cell);
            }
            table.completeRow();
            for (int i = 0; i < data.length; i++) {
                for (int j = 0; j < data[i].length; j++) {
                    String datum = data[i][j];
                    PdfPCell cell = new PdfPCell();
                    cell.setPhrase(new Phrase(datum.toUpperCase()));
                    table.addCell(cell);
                }
                table.completeRow();
            }

            mypdf.add(table);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(genererPdf.class.getName()).log(Level.SEVERE, null, ex);
        }

        mypdf.add(new Paragraph(" "));
        mypdf.add(new Paragraph(" "));
        mypdf.add(new Paragraph(
                "Pour toute question concernant cette facture,veuillez contacter Nom,numro de tlphone,adresse de messagerie ",
                FontFactory.getFont(null, 9, Font.NORMAL)));
        mypdf.add(new Paragraph(
                "                                                      Merci pour votre confiance",
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 14, Font.BOLDITALIC)));
        mypdf.add(new Paragraph("      "));
        mypdf.add(new Paragraph("  "));
        mypdf.add(new Paragraph("  "));

        mypdf.close();

    } catch (DocumentException ex) {
        Logger.getLogger(genererPdf.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:bl.pdf.PDFFile.java

public void createReport(String titel, EntityTableModel tModel) throws DocumentException {
    document.open();// w  w w  .  ja  v  a 2 s.c  o  m
    Paragraph preface = new Paragraph();

    preface.add(newLine(titel, catFont, -1));
    addEmptyLine(preface, 2);

    preface.add(getTable(tModel));

    document.add(preface);
    // Start a new page
    document.newPage();
    document.close();
}

From source file:bl.pdf.PDFFile.java

public void createRechnung(Rechnung r) throws DocumentException, DALException {
    document.open();//from w w  w. j  av  a  2 s  .c o  m
    Paragraph preface = new Paragraph();

    preface.add(newLine(new Date().toString(), small, Element.ALIGN_RIGHT));

    // Lets write a big header
    preface.add(newLine("Rechnung", catFont, -1));
    preface.add(newLine(r.getValues(), small, Element.ALIGN_LEFT));

    // Will create: Report generated by: _name, _date
    String to = "";
    if (r instanceof Ausgangsrechnung) {
        Kunde k = BL.getKunde(((Ausgangsrechnung) r).getKundeID());
        to += k.getValues();
    } else if (r instanceof Eingangsrechnung) {
        Kontakt k = BL.getKontakt(((Eingangsrechnung) r).getKontaktID());
        to += k.getValues();
    }
    preface.add(newLine(to, smallBold, Element.ALIGN_RIGHT));

    // We add one empty line
    addEmptyLine(preface, 2);

    // add table
    preface.add(getRechnungszeileTable(r));

    document.add(preface);
    // Start a new page
    document.newPage();
    document.close();
}

From source file:bl.pdf.PDFFile.java

@SuppressWarnings("unused")
private void addTitlePage(Document document) throws DocumentException {
    Paragraph preface = new Paragraph();
    // We add one empty line
    addEmptyLine(preface, 1);//from w  ww.j a v  a  2s.co  m
    // Lets write a big header
    preface.add(new Paragraph("Title of the document", catFont));

    addEmptyLine(preface, 1);
    // Will create: Report generated by: _name, _date
    preface.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            smallBold));
    addEmptyLine(preface, 3);
    preface.add(new Paragraph("This document describes something which is very important ", smallBold));

    addEmptyLine(preface, 8);

    preface.add(new Paragraph(
            "This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).",
            redFont));

    document.add(preface);
    // Start a new page
    document.newPage();
}

From source file:bl.pdf.PDFFile.java

private void addEmptyLine(Paragraph paragraph, int number) {
    for (int i = 0; i < number; i++) {
        paragraph.add(new Paragraph(" "));
    }/*from   ww w .j  av a  2  s .  c om*/
}

From source file:Boss.BOss.java

private void jTable2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable2MouseClicked
    if (evt.getClickCount() == 2) {
        try {//from w ww . j  a  v  a  2 s. com
            connect = new Connection();
            Statement st = connect.con.createStatement();
            String SQL = "SELECT * FROM request where idrequest =" + getSelectedrequest1();
            ResultSet rq = st.executeQuery(SQL);
            rq.next();
            /*****************************/
            String type = "";
            if (parseInt(rq.getString("id_type")) == 1) {
                type = "Instalation";
            }
            if (parseInt(rq.getString("id_type")) == 2) {
                type = "Transfer";
            }
            if (parseInt(rq.getString("id_type")) == 3) {
                type = "Maintenamce";
            }
            /**************************/
            Document document = new Document();
            PdfWriter.getInstance(document, new FileOutputStream("report.pdf"));
            document.open();

            Paragraph paragraph = new Paragraph();
            paragraph.add(new Paragraph("Request : \n",
                    FontFactory.getFont(FontFactory.COURIER_BOLD, 20, Font.BOLD, BaseColor.DARK_GRAY)));
            paragraph.add("ID Request :");
            paragraph.add(rq.getString("idRequest") + "");
            paragraph.add("\nRequest type :");
            paragraph.add(type);
            paragraph.add("\nClient name :");
            paragraph.add(rq.getString("clientName"));
            paragraph.add("\nPhone number :");
            paragraph.add(rq.getString("TELCLIENT"));
            paragraph.add("\nAddress 1 :");
            paragraph.add(rq.getString("address1"));
            paragraph.add("\nAddress 2 :");
            paragraph.add(rq.getString("address2"));
            paragraph.add("\nTeam :");
            paragraph.add(rq.getString("IDTEAM") + "\n");
            /***********************/
            String sql = "Select * from report where IDREQUEST = '" + getSelectedrequest1() + "' ";
            ResultSet rs = st.executeQuery(sql);
            rs.next();
            /**********************/

            paragraph.add(new Paragraph("Report : \n",
                    FontFactory.getFont(FontFactory.COURIER_BOLD, 20, Font.BOLD, BaseColor.DARK_GRAY)));
            paragraph.add(rs.getString("REPORT") + "\n");
            Paragraph date = new Paragraph(rs.getString("REPORTDATE").toString().substring(0, 10));
            date.setAlignment(Element.ALIGN_RIGHT);
            Paragraph title = new Paragraph("Report\n",
                    FontFactory.getFont(FontFactory.COURIER_BOLD, 20, Font.BOLD, BaseColor.BLACK));
            title.setAlignment(Element.ALIGN_CENTER);
            document.add(date);
            document.add(title);
            document.add(paragraph);
            document.close();
            /* Open Pdf */
            Desktop desktop = Desktop.getDesktop();
            if (desktop.isSupported(Desktop.Action.OPEN)) {
                desktop.open(new File("report.pdf"));
            } else {
                System.out.println("Open is not supported");
            }
        } catch (SQLException | ClassNotFoundException | DocumentException ex) {
            Logger.getLogger(BOss.class.getName()).log(Level.SEVERE, null, ex);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(BOss.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(BOss.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:br.com.treg.utils.GeneratorPDF.java

public GeneratorPDF(String valorExtenso, ObraFuncionario of, double valor) {
    //criao do documento
    Document document = new Document();

    try {//ww w.j a  v  a  2s . c  om
        PdfWriter.getInstance(document, new FileOutputStream("C:\\Users\\Gustavo\\Desktop\\Recibo.pdf"));
        document.open();

        Paragraph preface = new Paragraph();

        addEmptyLine(preface, 1);

        preface.add(new Paragraph("RECIBO", catFont));
        addEmptyLine(preface, 1);

        preface.add(new Paragraph("Valor: R$ " + valor));
        addEmptyLine(preface, 3);

        preface.add(new Paragraph("Recebi da empresa TR&G "));
        addEmptyLine(preface, 1);
        preface.add(new Paragraph("A importncia de " + valorExtenso));
        addEmptyLine(preface, 1);
        preface.add(
                new Paragraph("referente a servios prestados de " + of.getFuncionario().getFuncao() + "."));

        addEmptyLine(preface, 4);

        Calendar data = Calendar.getInstance();
        String mes = NomeDoMes(data.get(Calendar.MONTH), 0);
        int ds = data.get(Calendar.DAY_OF_WEEK);

        preface.add(new Paragraph("Campo Grande, " + data.get(Calendar.DATE) + " de " + mes + " de "
                + data.get(Calendar.YEAR) + " (" + DiaDaSemana(ds, 1) + ")."));
        addEmptyLine(preface, 1);
        preface.add(new Paragraph("Funcionrio: " + of.getFuncionario().getNome() + " - CPF/RG: "
                + of.getFuncionario().getCpf()));
        addEmptyLine(preface, 1);
        preface.add(new Paragraph("Endereo: " + of.getFuncionario().getEndereco()));
        addEmptyLine(preface, 1);
        preface.add(new Paragraph("Assinatura: _____________________________"));

        document.add(preface);
    } catch (DocumentException | IOException de) {
        System.err.println(de.getMessage());
    }
    document.close();

}

From source file:br.unifor.mia.xmpsemantico.xmp.MetadataXmp.java

License:GNU General Public License

/**
 * create PDF document/* www  .  j a va 2  s .  com*/
 * @param filename of new archive PDF
 * @throws DocumentException 
 * @throws IOException 
 */
public void createPdf() throws IOException {

    Document document = new Document();
    PdfWriter writer = null;
    try {
        writer = PdfWriter.getInstance(document, new FileOutputStream(pathPdf));

        ByteArrayOutputStream os = new ByteArrayOutputStream();
        XmpWriter xmp = new XmpWriter(os);

        MiaSchema miaSchema = new MiaSchema();
        miaSchema.addDescription(this.descricao);
        miaSchema.setProperty(MiaSchema.DISCIPLINA, this.disciplina);
        miaSchema.setProperty(MiaSchema.PROFESSOR, this.professor);
        miaSchema.setProperty(MiaSchema.CARGA_HORARIA, this.cargaHoraria);
        miaSchema.setProperty(MiaSchema.CREDITOS, this.creditos);
        xmp.addRdfDescription(miaSchema);

        xmp.close();
        writer.setXmpMetadata(os.toByteArray());

        document.open();
        document.addAuthor("docsemantico");
        Paragraph paragraph = new Paragraph("Quick brown ");
        Anchor foxRefence = new Anchor("fox");
        foxRefence.setReference("#fox");
        paragraph.add(foxRefence);
        paragraph.add(" jumps over the lazy dog.");
        document.add(paragraph);
        document.newPage();
        Anchor foxName = new Anchor("This is the FOX");
        foxName.setName("fox");
        document.add(foxName);
        document.add(new Paragraph(this.texto));

        document.close();
    } catch (DocumentException e) {
        e.printStackTrace();
    }

    //teste commit
}