Example usage for com.itextpdf.text Paragraph Paragraph

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

Introduction

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

Prototype

public Paragraph(Phrase phrase) 

Source Link

Document

Constructs a Paragraph with a certain Phrase.

Usage

From source file:be.roots.taconic.pricingguide.service.PDFServiceImpl.java

License:Open Source License

private byte[] createModelPages(Contact contact, List<Model> models, Toc tableOfContents)
        throws IOException, DocumentException {

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    Document document = iTextUtil.createNewDocument();
    PdfWriter writer = PdfWriter.getInstance(document, bos);

    document.open();//w  w w. java  2s .c  om

    // create a PdfPTable for every model (so we can measure the height)
    final List<PdfPTable> modelPageTables = new ArrayList<>();
    Collections.sort(models);
    for (Model model : models) {
        if (model != null) {
            modelPageTables.add(createModelPage(contact, model, writer));
        }
    }

    // put the PdfPTable Models tables on PDF pages (multiple per page if possible)
    byte[] pages = new byte[] {};

    int height = 0;
    List<String> pageNames = new ArrayList<>();

    int i = 0;
    for (PdfPTable modelPageTable : modelPageTables) {

        // create a new pdf page, if necessary
        if (height != 0 && (height + modelPageTable.getTotalHeight()
                + 20 /* for the line separator */ ) >= iTextUtil.PAGE_HEIGHT) {

            writer.close();
            document.close();
            bos.close();

            byte[] page = bos.toByteArray();
            tableOfContents.addEntries(2, pageNames, page, true,
                    Toc.MODEL_SORT_PREFIX + "___" + IntUtil.format(++i));
            pages = iTextUtil.merge(pages, page);

            height = 0;
            pageNames.clear();
            bos = new ByteArrayOutputStream();
            document = iTextUtil.createNewDocument();
            writer = PdfWriter.getInstance(document, bos);

            document.open();

        } else if (height != 0) {
            // if not the first model on the page, draw a separator

            document.add(new Paragraph(
                    new Chunk(new LineSeparator(.25f, 80f, BaseColor.LIGHT_GRAY, Element.ALIGN_CENTER, -2))));
            document.add(new Paragraph(new Chunk("   ")));
        }

        // rerender the table (with a valid pdfWriter)
        document.add(createModelPage(contact, models.get(modelPageTables.indexOf(modelPageTable)), writer));
        height += modelPageTable.getTotalHeight();
        pageNames.add(models.get(modelPageTables.indexOf(modelPageTable)).getProductNameProcessed());

    }
    writer.close();
    document.close();

    byte[] page = bos.toByteArray();
    tableOfContents.addEntries(2, pageNames, page, true, Toc.MODEL_SORT_PREFIX + "___" + IntUtil.format(++i));
    pages = iTextUtil.merge(pages, page);

    return pages;

}

From source file:be.thomasmore.controller.InputBean.java

public void createPdf(String filename) throws DocumentException, IOException {
    // step 1/*from   w  ww  .  ja v a  2  s .  c  o  m*/
    Document document = new Document();
    // step 2
    PdfWriter.getInstance(document, new FileOutputStream(filename));
    // step 3
    document.open();
    // step 4
    document.add(new Paragraph("Hello World!"));
    // step 5
    document.close();
}

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

@Override
public void createPDF(List<Score> scores) {
    try {//w  w w. j a  v a  2  s .  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(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 w ww . ja  v 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(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:bean.RecommendationBean.java

public void createPdf(String file) throws DocumentException, IOException {
    //String escaped = HtmlUtil.escape(editorVal);
    //String escapedCss = HtmlUtil.escapeCSS(editorVal);

    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream(file));
    document.open();//from w w w . j  av  a2  s  .c om
    document.add(new Paragraph("insert letter head"));
    document.add(new Paragraph("Recommendation Report"));
    document.add(new Paragraph("date:" + "CURRENT DATE"));
    document.add(new Paragraph("date encoded:" + reportDateEncoded));
    document.add(new Paragraph(selectedProspect.getLastName() + "," + selectedProspect.getFirstName()
            + selectedProspect.getMiddleName()));
    //document.add(new Paragraph("escaped" + "\n" + editorVal));
    //document.add(new Paragraph("escaped()" + "\n" + escaped));
    //document.add(new Paragraph("escapedCss()" + "\n" + escapedCss));
    document.close();
}

From source file:bean.ReportingBean.java

public void createPdf(String filename) throws DocumentException, IOException {
    //String escaped = HtmlUtil.escape(editorVal);
    //String escapedCss = HtmlUtil.escapeCSS(editorVal);

    //StringReader stringReader = new StringReader(editorVal);
    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream(filename));
    //PdfWriter.getInstance(document, new FileOutputStream(RESULT));
    //PdfWriter.getInstance(document, new FileOutputStream("JSF-PDF.pdf"));
    document.open();/*from ww w  . j a va  2s.  c o m*/
    document.add(new Paragraph("insert letter head"));
    document.add(new Paragraph("insert title"));
    document.add(new Paragraph("date:"));
    document.add(new Paragraph("date encoded:"));
    document.add(new Paragraph("date from" + "-" + "date to"));
    document.add(new Paragraph("time from" + "-" + "time to"));
    //document.add(new Paragraph("escaped" + "\n" + editorVal));
    //document.add(new Paragraph("escaped()" + "\n" + escaped));
    //document.add(new Paragraph("escapedCss()" + "\n" + escapedCss));
    document.close();
}

From source file:beans.ManagedBeanReportes.java

public void inventario() throws DocumentException, IOException {
    FacesContext facexcontext = FacesContext.getCurrentInstance();
    ValueExpression vex = facexcontext.getApplication().getExpressionFactory()
            .createValueExpression(facexcontext.getELContext(), "#{managedBeanLogin}", ManagedBeanLogin.class);
    ManagedBeanLogin beanLogin = (ManagedBeanLogin) vex.getValue(facexcontext.getELContext());

    FacesContext context = FacesContext.getCurrentInstance();

    Document document = new Document(PageSize.A4, 25, 25, 75, 25);//int marginLeft,   int marginRight,   int marginTop,   int marginBottom

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfWriter writer = PdfWriter.getInstance(document, baos);
    writer.setPageEvent(new ManagedBeanReportes.Watermark(""));
    if (!document.isOpen()) {
        document.open();//w  w  w  .j a v  a2  s. c  o  m
    }

    try {

        ExternalContext extContext = FacesContext.getCurrentInstance().getExternalContext();
        //String imageUrl1 = extContext.getRealPath("//resources//images/logo0002.png");
        //Image welladigital = Image.getInstance(imageUrl1);
        //welladigital.setAbsolutePosition(377f, 760f);
        //welladigital.scalePercent(40);
        //document.add(welladigital);

        //crear tabla PARA NOMBRE DEL AO
        PdfPTable table = new PdfPTable(3);
        table.setWidthPercentage(100);
        table.setTotalWidth(450f);
        // table.setTotalWidth(540f);
        table.setLockedWidth(true);
        float[] headerWidths = { 120, 20, 310 };
        table.setWidths(headerWidths);
        table.getDefaultCell();

        SimpleDateFormat formato = new SimpleDateFormat("EEEE dd MMMM YYYY");
        StringBuilder cadena = new StringBuilder(formato.format(fecha_inicio));

        Chunk underline = new Chunk("FECHA DE INVENTARIO:" + cadena.toString().toUpperCase(), bigFont12);
        underline.setUnderline(0.2f, -2f); //0.1 thick, -2 y-location
        PdfPCell table5 = new PdfPCell(new Paragraph(underline));
        table5.setHorizontalAlignment(Paragraph.ALIGN_CENTER);
        table5.setColspan(3);
        table5.setBorder(Rectangle.NO_BORDER);
        table.addCell(table5);

        document.add(table);

        document.add(new Paragraph("\n", pequeFont));

        PdfPCell table2 = new PdfPCell();

        table2 = new PdfPCell(
                new Paragraph(beanLogin.getObjetoEmpleado().getTienda().getNombreTienda(), pequeFont));
        table2.setHorizontalAlignment(Paragraph.ALIGN_CENTER);
        table2.setColspan(3);
        table2.setBorder(Rectangle.NO_BORDER);
        table = new PdfPTable(3);
        table.setWidthPercentage(100);
        table.setTotalWidth(450f);
        table.setLockedWidth(true);
        table.setWidths(headerWidths);
        table.getDefaultCell();
        table.addCell(table2);
        document.add(table);

        document.add(new Paragraph("\n", pequeFont));

        document.add(traerSubtabla(beanLogin.getObjetoEmpleado().getTienda()));
        formato = new SimpleDateFormat("yyyy-MM-dd");
        cadena = new StringBuilder(formato.format(fecha_inicio));

        //document.add(traerSubtabla02(cadena.toString()));
        document.add(new Paragraph("\n", pequeFont));
        ExternalContext ctx = FacesContext.getCurrentInstance().getExternalContext();
        String ctxPath = ((ServletContext) ctx.getContext()).getContextPath();
        document.close();
        formato = new SimpleDateFormat("dd_MM_yyyy");
        cadena = new StringBuilder(formato.format(fecha_inicio));
        String fileName = cadena.toString();

        writePDFToResponse(context.getExternalContext(), baos, fileName);
        context.responseComplete();

    } catch (Exception de) {
        de.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 . j  av  a2s. c o 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:biblioteca.BibliotecaFXMLController.java

@FXML /// Arquivo - PDF - Tabela Alunos
public void pdf() throws FileNotFoundException, DocumentException, IOException, SQLException {
    Document doc = null;//from ww w.  ja v a  2s .c o  m
    OutputStream os = null;
    try {
        contest conn = new contest();
        //cria o documento tamanho A4, margens de 2,54cm
        doc = new Document(PageSize.A4);
        //cria a stream de sada
        os = new FileOutputStream("TabelaA.pdf");
        //associa a stream de sada ao
        PdfWriter.getInstance(doc, os);
        //abre o documento
        doc.open();
        //adiciona o texto ao PDF 
        PdfPTable tabelaA = new PdfPTable(new float[] { 0.2f, 0.7f, 0.7f, 0.9f, 0.7f });
        PdfPCell header = new PdfPCell(new Paragraph("Tabela de Alunos"));
        header.setColspan(5);
        tabelaA.addCell(header);
        tabelaA.addCell("ID");
        tabelaA.addCell("Matrcula");
        tabelaA.addCell("Nome");
        tabelaA.addCell("C.P.F");
        tabelaA.addCell("Telefone");
        Statement stA = conn.conectar1().createStatement();
        ResultSet rsa = stA.executeQuery("SELECT idAluno,matriculaAluno,nomeAluno,nCPF,Telefone FROM `Aluno`;");
        while (rsa.next()) {
            Aluno a = new Aluno(0, 0, "", "", "");
            a.setIdaluno(rsa.getInt("idAluno"));
            a.setMatricula(rsa.getInt("matriculaAluno"));
            a.setNoAluno(rsa.getString("nomeAluno"));
            a.setCpf(rsa.getString("nCPF"));
            a.setTelefone(rsa.getString("Telefone"));

            tabelaA.addCell(String.valueOf(a.getIdaluno()));
            tabelaA.addCell(String.valueOf(a.getMatricula()));
            tabelaA.addCell(a.getNoAluno());
            tabelaA.addCell(a.getCpf());
            tabelaA.addCell(a.getTelefone());

        }
        doc.add(tabelaA);
    } finally {
        if (doc != null) {
            //fechamento do documento
            doc.close();
        }
        if (os != null) {
            //fechamento da stream de sada
            os.close();
        }
    }
}

From source file:biblioteca.BibliotecaFXMLController.java

@FXML /// Arquivo - PDF - Tabela Livros
public void pdfL() throws FileNotFoundException, DocumentException, IOException, SQLException {
    Document doc = null;//from ww  w.  j a v  a  2 s .c o m
    OutputStream os = null;
    try {
        contest conn = new contest();
        //cria o documento tamanho A4, margens de 2,54cm
        doc = new Document(PageSize.A4);
        //cria a stream de sada
        os = new FileOutputStream("TabelaL.pdf");
        //associa a stream de sada ao
        PdfWriter.getInstance(doc, os);
        //abre o documento
        doc.open();
        //adiciona o texto ao PDF
        PdfPTable tabelaL = new PdfPTable(new float[] { 0.1f, 0.7f, 0.7f, 0.1f });
        PdfPCell header = new PdfPCell(new Paragraph("Tabela de Livros"));
        header.setColspan(4);
        tabelaL.addCell(header);
        tabelaL.addCell("ID");
        tabelaL.addCell("Ttulo");
        tabelaL.addCell("Autor");
        tabelaL.addCell("Qtde.");

        Statement st = conn.conectar1().createStatement();
        ResultSet rs = st.executeQuery("SELECT * FROM `Livro`;");
        while (rs.next()) {
            Livro l = new Livro(0, "", "", 0, 0);
            l.setIdlivro(rs.getInt("idlivro"));
            l.setTiLivro(rs.getString("nomeLivro"));
            l.setNoAutor(rs.getString("nomeAutor"));
            l.setQtdeLivro(rs.getInt("qtdelivro"));

            tabelaL.addCell(String.valueOf(l.getIdlivro()));
            tabelaL.addCell(l.getTiLivro());
            tabelaL.addCell(l.getNoAutor());
            tabelaL.addCell(String.valueOf(l.getQtdeLivro()));
        }
        doc.add(tabelaL);
    } finally {
        if (doc != null) {
            //fechamento do documento
            doc.close();
        }
        if (os != null) {
            //fechamento da stream de sada
            os.close();
        }
    }
}